Stephen Cope
136 sostenitori
How To Use A Backup MQTT Broker for Reli ...

How To Use A Backup MQTT Broker for Reliability

Jun 02, 2024

MQTT offers three QOS settings - 0,1,2 as described in the understanding QOS tutorial.

QOS levels 1 and 2 require an acknowledgement from the MQTT broker and provide for reliable message transfer.

However there are many circumstances were just relying on these QOS levels isn't sufficient.

As an example what happens if the broker goes down?

Although many cloud providers provide high availability brokers these options tend to be expensive.

A simple alternative is to publish to multiple brokers as shown in the diagram below:

Project Overview

backup-broker-diagram
To do this we need a publishing client configured to use tow brokers and a corresponding receiving client .

Publishing Messages

To do this we have three main options.

  1. Connect and Publish to a primary broker and connect to a second backup broker if the primary is unavailable.

  2. Publish to a primary broker and switch to a second backup broker on fail and queue if necessary.

  3. Publish to both brokers and filter messages on the client to avoid duplicates.

Receiving Messages

To receive the messages we simply subscribe to both brokers using the same topics as the publishing clients.

Depending on how we publish we may not need to filter incoming messages for duplicate messages.

If we only publish using methods 1 and 2 as listed above then no duplicates we be sent.

Example Code and Project

The project covers publishing and receiving and is available on my site How to Use the Python MQTT Client with a Backup Broker and includes example Python code.

Ti piace questo post?

Offri un caffè a Stephen Cope

Altro da Stephen Cope