15

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.

Emzor
  • 1,380
  • 17
  • 28
Abhishek Maheshwari
  • 275
  • 1
  • 3
  • 12

7 Answers7

19

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.

Dominik Obermaier
  • 5,610
  • 4
  • 34
  • 45
  • how does HiveMQ behaves on Azure? By default Azure VM's have ICMP blocked, and with a regular Mosquitto instance, we experience a lot of disconnects because of that. Can you confirm that HiveMQ works all fine on latest Azure VMs ? – qgicup Jan 19 '16 at 09:51
  • 1
    According to documentation: "mosquitto clustering is achieved on backend level (redis, amqp, etc)." – Dániel Kis Apr 01 '18 at 08:41
  • @DánielKis: I don't see this in the official documentation and as far as I know there is no official support for that in mosquitto. Note that even if you would use a database for "clustering", you're trading the single point of failure as it would be the database. But this is more a theoretical concern as mosquitto does not support any "backend" out of the box. – Dominik Obermaier Jun 01 '18 at 23:00
  • You can do clustering with mosquitto https://github.com/hui6075/mosquitto-cluster ) – podarok Jul 12 '19 at 13:52
11

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.

  1. Mosquitto bridge support.
  2. Plugin support - mosquitto-auth-plug(1)

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        +-------------+
                                           +-----^--^--------+
                                                 |  |
                                                 |  |
                                                 +  +
Community
  • 1
  • 1
kiranpradeep
  • 10,859
  • 4
  • 50
  • 82
6

There are 2 (for this time of writing) major open source projects that support large scale MQTT deployments and clustering

VerneMQ and EMQ are both written in Erlang, which is very suitable for distributed messaging, having all the replication as built in toolset part of the (Erlang) language.

VerneMQ has commercial enterprise support, while EMQ is planning to in the near future, also both projects have large companies backing them as sponsors.

You may also look into HiveMQ which is the oldest kid in the block, yet cannot be used without a payed license.

syberkitten
  • 234
  • 4
  • 9
2

It's not on the list mentioned by Dominik but Solace Systems has an MQTT appliance that supports clustering. Each broker supports several hundred thousand concurrent client connections.

Disclaimer: I am a Systems Engineer at Solace

2

The way I have addressed clustering for mosquitto has been to setup a haproxy frontend that reverse proxies to several listening brokers.

I have also gone one step further to utilize DNS SD which the latest versions of mosquitto support with the -S flag.

However there has been some headaches with this design, namely in application support for dnssd and libresolv on most distros do not honor the domain and search fields in resolv.conf.

Therefore if your working around a legacy environment then I would suggest looking into either rabbitmq, hivemq, or redis pubsub for more production level solution that can be shoehorned into existing footprints.

Dwight Spencer
  • 1,472
  • 16
  • 22
1

Your may look into Bevywise IoT Platform. It is a Commercial offering. This has an option to add as many brokers as possible to scale up. This supports MQTT and MQTT-SN protocols.

Disclaimer: I work for Bevywise Networks.

Nathan Tuggy
  • 2,237
  • 27
  • 30
  • 38
0

You can also check EMQX for clustering support of MQTT.

EMQX MQTT Broker

ᐅdevrimbaris
  • 718
  • 9
  • 20