Hello together,
I’ve observed some unexpected behavior on my mosquitto bridge when the bridge was disconnected and reconnected again. Simple scenario:
client1 ↔ Broker Pi ↔ Broker local ↔ client2
The clients are also simple for demonstration:
client2 is publishing something on a “desired” topic, which client1 is subscribing to. When client1 receives a message on that topic it simply publishes the content on a retained “reported” topic, which client2 subscribes to and sets an internal attribute. The qos for all subscriptions are set to 1 to ensure receiving the messages.
To reproduce the behavior, we start all components on the different devices (I use my local machine and a raspberrypi). Now we perform the following steps:
- disconnect the internet connection to disconnect the broker bridge.
- publish some messages from client2 on the “desired” topic
- reconnect to the internet and wait for the bridge to reconnect
I assume client1 receives all published messages while not connected and publishes the messages on “reported” in the order they are published by client2. On the other hand, I’m expecting client2 to receive all messages, resulting in the internal attribute being set to the latest message sent by client2 itself.
For instance:
- start:
- client2 publish “initial” → client1 publishes retained “initial” → client2 sets internal attribute to “initial”
- disconnect
- client2 publish “foo” → internal attribute = “initial”
- client2 publish “bar” → internal attribute = “initial”
- reconnect
- client1 receives “foo”, publishes “foo”
- client1 receives “bar”, publishes “bar”
- client2 receives “foo” → internal attribute = “foo”
- client2 receives “bar” → internal attribute = “bar”
I observe that client2 also receives the retained message “initial” before step 8, which is okay, but also after step 9. So the newly sent messages of client1 are overridden and the currently held retained message in the broker is “initial”, not “bar”.
Any ideas why this happens?
Configuration
- I provide two simple Python scripts with paho-mqtt 1.6.1 for client 1 +2
- you may have to replace/set the environment variables to connect to your brokers
- clients.zip (1015 Bytes)
- mosquitto version 2.0.18
- mosquitto bridge configuration:
topic # both 1
remote_clientid some_id
start_type automatic
try_private true
bridge_protocol_version mqttv50
cleansession false