bzo
bzo

Reputation: 1626

Using MQTT with multiple subscribers

I'm using mosquitto (http://mosquitto.org/) as an MQTT broker and am looking for advice on load balancing subscribers (to the same topic). How is this achieved? Everything I've read about the protocol states that all subscribers to the same topic will be given a published message.

This seems inefficient, and so I'm looking for a way for a published message to be given to one of the connected subscribers in a round-robin approach that would ensure a load balanced state.

If this is not possible with MQTT, how does a subscriber avoid being overwhelmed with messages?

Upvotes: 12

Views: 19130

Answers (3)

Nitin
Nitin

Reputation: 2911

MQTT v5 has the support of shared subscriptions and mosquitto version 1.6 added support of MQTT v5.

Check release notes

Good article on shared subscriptions here

Upvotes: 5

Dominik Obermaier
Dominik Obermaier

Reputation: 5770

Typically you design MQTT applications in a way that you don't have overwhelmed subscribers. You can achieve this by spreading load to different topics.

If you really can't do that, take a look at the shared subscription approach sophisticated MQTT brokers like MessageSight and HiveMQ have. This is exactly the feature you're looking for but is broker dependant and is not part of the official MQTT spec.

Upvotes: 12

hardillb
hardillb

Reputation: 59608

MQTT is a Pub/Sub protocol, the basis is for a 1 to many distribution of messages not a 1 to 1 (of many) you describe. What you describe would be more like a Message Queuing system which is distinctly different from Pub/Sub.

Mosquitto as a pure implementation of this protocol does not support the delivery as you describe it. One solution is to us a local queue with in the subscriber which incoming messages are added to and then consumed by a thread pool.

I do believe that the IBM Message Sight appliance may offer the type of message delivery you are looking for as an extension to the protocol called Shared Subscriptions, but with this enabled it is deviating from the pure MQTT spec.

Upvotes: 4

Related Questions