Can Mosquitto support multiple brokers?



I've been considering Mosquitto for a MQTT message broker for a home IoT network, but I'm concerned that the broker could be a single point of failure which could bring down my whole network if it failed, since all messages have to go through the broker and no messages can be transmitted at all if the broker goes offline for any reason (e.g. accidental unplugging, hardware failure, etc.)

Would be possible to use multiple brokers with Mosquitto installed to improve the reliability of the network? If it is possible, are there any disadvantages/significant overheads to using multiple brokers?


Posted 2016-12-13T17:52:50.617

Reputation: 11 277



Yes, Mosquitto does support multiple brokers.

Mosquitto uses MQTT Bridges to connect multiple brokers thus routing messages between these mosquitto brokers. This way a bridge between your primary broker to a fallback system can be established. Avoid creating loops though. If both brokers run your clients publish to the primary broker which then publishes the topic to each and any subscriber including the bridged secondary broker. If the primary fails your clients will note (Connection Refused, Server unavailable) and can fallback to directly publish to the secondary. (I am not yet sure how to fix it the other way round.) As you're not expecting the client to disconnect ungracefully I think that "Last Will and Testament" do not apply here (it would be used to have the broker notify on behalf of a disconnected client).

This post however lists the drawbacks of this approach especially with respect to scalability and availability:

  • The bridge routing mechanisms don’t scale well if you forward all messages to the other bridges
  • The communication overhead between bridges is significant if you’re using QoS 2 between bridges (which you need to do if you want to propagate messages between clients that are connected to different bridges)
  • There is no failover and high availability. If a broker bridge crashes, messages may get lost
  • MQTT clients cannot be migrated to other bridge nodes. MQTT sessions are not replicated across bridges, so you will lose all your queued messages and subscriptions if you’re using MQTT persistent sessions.


Posted 2016-12-13T17:52:50.617

Reputation: 1 797


In .NET the implementation allows to connect one client to one broker, so I'd say why not...

MqttClient mqtt;
string broker = ini.getData("MQTT", "hostname");
mqtt = new MqttClient(broker);
mqtt.MqttMsgPublishReceived += mqtt_received;

Thing is, you must manage duplicates in case of a fallback when the other broker will start sending messages, or warn the clients.

There can be several possibilities like each broker subscribes to each other and set a Last Will and Testament to warn themselves and their clients that a fallback will occur!


Posted 2016-12-13T17:52:50.617

Reputation: 2 751

How can a broker subscribe or more like connect to another broker?Bence Kaulics 2016-12-14T11:25:12.270

1I was thinking of a client nested on the broker's server.Goufalite 2016-12-14T12:34:47.477

@Goufalite, this is really useful for MQTT in general, thanks. Would you happen to know any more about Mosquitto, the broker I discussed in the question?Aurora0001 2016-12-14T14:50:43.947

This is the lowest thing I know about MQTT (I didn't realized there were other broker like HiveMQ before coming on IoT SE). What else would you like to know? You mean implementation?Goufalite 2016-12-14T15:48:23.547

@Goufalite just interested whether Mosquitto itself has a way of running multiple brokers in parallel. If you could suggest a way to do it with Mosquitto or link documentation that'd be great.Aurora0001 2016-12-14T16:34:14.913