Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using MQTT with multiple subscribers

Tags:

mqtt

mosquitto

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?

like image 328
bzo Avatar asked Jan 26 '16 13:01

bzo


People also ask

Can MQTT have multiple subscribers?

A publisher sends messages on a specific topic to an MQTT broker, which forwards them to a client or clients that are subscribed to this topic. Each topic can only have one publisher but multiple subscribers.

Can MQTT client connect to multiple brokers?

No, The client can only connect to a single broker at a time. You can run multiple clients.

Can a MQTT client subscribe multiple topics?

Can MQTT subscribe to multiple topics? Yes. You can use MQTT wildcards to subscribe to multiple topics simultaneously. A wildcard can only be used to subscribe to topics, not to publish a message.

How many clients can a MQTT broker handle?

Each one will handle 10-20 clients. As far as I understand a common solution is MQTT. The clients periodically send data to the broker (i.e. Mosquitto running on the hosting server), that in turn updates the main web app that runs on the same server.


3 Answers

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

like image 195
Nitin Avatar answered Sep 18 '22 08:09

Nitin


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.

like image 32
hardillb Avatar answered Sep 22 '22 08:09

hardillb


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.

like image 21
Dominik Obermaier Avatar answered Sep 19 '22 08:09

Dominik Obermaier