I am using Mosquitto broker to implement MQTT protocol. But I am unable to find how clustering can be done in case of mosquitto brokers. Also is there any limitation on number of clients those can be served with one broker.
You can't do clustering with mosquitto.
Some other MQTT brokers out there which support clustering, including HiveMQ. HiveMQ has an elastic cluster ability with auto discovery and a distributed masterless architecture and works very well on cloud providers like AWS or Azure.
You can see a full list of all brokers which support clustering here.
Disclaimer: I'm a developer of HiveMQ, so this answer may be biased.
Original source of this answer: Horizontal scaling for brokers. I just added the plugin support.
Two functionalities of mosquitto broker combined could be used to setup a n
node cluster.
The bridge functionality is used ONLY to synchronize messages between all mosquitto brokers while the mosquitto-auth-plugin could be used to save authorization and ACL in a single database back end.
While setting up the bridge, notice the usage of in/out bridge topics to avoid forwarding loops(2). The pattern is of format
topic pattern [[[ out | in | both ] qos-level] local-prefix remote-prefix]
Quoting mosquitto.conf man page(3), For incoming topics, the bridge will prepend the pattern with the remote prefix and subscribe to the resulting topic on the remote broker. When a matching incoming message is received, the remote prefix will be removed from the topic and then the local prefix added. And vice versa for an outgoing topic
Sample mosquitto.conf for a 3 node cluster is below. To be load tested with mqtt-malaria(4) and more importantly the effect on clients connecting with clean_session flag to false, .
+-------------------+
+------------------> BRIDGE BROKER <------------+
| | 192.168.1.1 | |
| +--------^----------+ |
| | |
| | |
| | |
Broker A | Broker B | | Broker C
| | |
+----------------------+--+ +----------------+--------+ +--+----------------------+
| connection A | | connection B | | connection C |
| | | | | |
| address 192.168.1.1:1883| | address 192.168.1.1:1883| | address 192.168.1.1:1883|
| | | | | |
| topic # out 2 "" A/ | | topic # out 2 "" B/ | | topic # out 2 "" C/ |
| topic # in 2 "" B/ | | topic # in 2 "" A/ | | topic # in 2 "" A/ |
| topic # in 2 "" C/ | | topic # in 2 "" C/ | | topic # in 2 "" B/ |
+----------------------^--+ +----------------^--------+ +--+----------------------+
| | ^
| | |
| | |
| +-------+---------+ |
+-------------------+ HA PROXY +-------------+
+-----^--^--------+
| |
| |
+ +
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With