Diogo Aleixo
Diogo Aleixo

Reputation: 871

Mosquitto fire only one for each topic

I implemented a MQTT message broker using mosquitto on my network. I have one web app publishing things to the broker and several servers that subscribed the same topic. So i have a redundancy scenario.

My question is, using mosquitto alone, is there any way to configure it to publish data only on the first subscriber? Otherwise, all of them will do the same thing.

Upvotes: 0

Views: 802

Answers (2)

hardillb
hardillb

Reputation: 59668

No this is not possible with mosquitto at the moment (without communication between the 2 subscribers as described in the other answer).

For the new release of the MQTT spec (v5)* there is a new mode called "Shared Subscriptions". This allow s multiple clients to subscribe to a single topic and messages will be delivered by round robin to each client. This is more for load balancing rather than master/slave fail over.

*There are some brokers (HiveMQ, IBM MessageSight) that already support some version of Shared Subscriptions at MQTT v3.1.1, but they implement it in slightly different ways (different topic prefixes) so they are not cross compatible.

Upvotes: 1

Nitro
Nitro

Reputation: 1093

I don't think that is possible.

But you can do this.

Have the first subscriber program respond with an ack on the channel as soon as it gets the message, and have the redundancy program look for the ack for a small time after the initial message.

IF the ack is received the redundancy should not do anything.

So if the first subscriber gets and uses the message, the others wont do anything even if they get the message.

Upvotes: 1

Related Questions