24

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?

Aurora0001
  • 18,520
  • 13
  • 55
  • 169

2 Answers2

15

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.
Ghanima
  • 2,539
  • 1
  • 19
  • 46
10

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;
mqtt.Connect(Guid.NewGuid().ToString());

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!

Goufalite
  • 3,776
  • 17
  • 33