Blowa
Blowa

Reputation: 70

MQTT message subscription "all except me"

I'm writing a ServiceBus over MQTT protocol for a personal project.

I would basically like to subscribe every messages except the ones that comes from my instance.

I thought about doing a application side check, adding a "SenderId" property in my message. But it has a considerable overhead in bandwidth consumption and also in compute time cause I have to check every single message if I'm the sender

I'm using basic topic family/message layout nothing complicated

I thought about using some kind of topic layout like : family/message/{senderIdHere}

But it looks like I'm wrong somewhere cause I would like to subscribe all

Here is a small example. That "EventPipeline" is somehow necessary to reduce code duplication between internal instance handling and over service bus handling small example If anyone have some great hints,

Thanks by advance.

Upvotes: 0

Views: 1962

Answers (1)

hardillb
hardillb

Reputation: 59638

MQTT doesn't work that way, if you subscribe to a topic you normally get everything published to that topic.

The one possible option I can think of is to have everything publish to it's own sub topic e.g. family/message/{senderIdHere} and subscribe to the wildcard family/message/#

Then use ACLs to allow each user to publish (write) to their subtopic, but not be able to subscribe (read) from it. This will have the broker filter the messages for you.

Edit:

MQTT v5 introduced an option when subscribing to a topic to ignore the publisher's own messages. But this does require both the broker and the client to be using MQTT v5

Upvotes: 2

Related Questions