Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MQTT Broker Bridge data persistence

Tags:

mqtt

mosquitto

We have Mosquito broker in Location A and Rabbit MQ is in Cloud. We have bridged both the brokers. Data from the Topic configured in Mosquito is getting published in AMQ.Topic in Rabbit MQ.

In case of loss of connectivity, will the data available at Mosquito broker will be passed on after re-establishing the connectivity.

What are the things we should keep in mind while developing such solutions ?

like image 209
Siva Karthikeyan Avatar asked Dec 24 '22 15:12

Siva Karthikeyan


1 Answers

This depends on how you have configured the bridges.

In general, MQTT clients come in two types, durable/persistent or non-durable/non-persistent. This is controlled using the clean session flag when connecting.

Durable/Persistent Clients

When a durable client connects (clean session is set to 0), the broker will maintain information about that client after it disconnects. This means the subscriptions for that client and possibly messages ready for delivery when it reconnects (using the same client id!)

By default, and according to the MQTT spec, messages are only queued for a disconnected durable client if both the subscription and the message use a QoS of greater than 0. Mosquitto offers the ability to queue all messages, but this is not covered by the spec so you can't rely on it for other brokers.

There are other caveats - only a limited number of messages will be queued for an offline client. This can be configured on mosquitto using the max_queued_messages option.

Non-Durable/Non-Persistent Clients

When a non-durable client (clean session set to 1) connects, the server will not retain any information about that client after it disconnects.

If a client connects as durable, then reconnects as non-durable, then all stored information will be deleted as soon as the non-durable version connects.

Bridges

The same principle applies to bridges, so you need to configure the bridges to be durable (clean session 0), and to use QoS>0 for your messages. You would also need to ensure that the maximum queued messages is appropriate for your needs.

like image 112
ralight Avatar answered Apr 02 '23 22:04

ralight