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 numb
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 +-------------+
+-----^--^--------+
| |
| |
+ +