Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Mosquitto » Mosquitto bridge and retain behaviour
Mosquitto bridge and retain behaviour [message #1840976] Thu, 29 April 2021 16:42 Go to next message
Florent Dupont is currently offline Florent DupontFriend
Messages: 5
Registered: April 2021
Junior Member
Hi everyone,

I have a "problem" related to MQTT bridge and retained messages. I actually can't tell whether this is expected behaviour or if it's a bug, so I post here rather than github.

I have 2 Mosquitto bridged together. The relevant bit of config is:
- connection bridge-01
- address myawesomemqtt:1883
- try_private true
- topic # out 2 London/ test/London/
- bridge_protocol_version mqttv50
- bridge_outgoing_retain true

Assume MQTT1 is the local server with the bridge configured and MQTT2 is the remote MQTT server that is part of the bridge (but nothing special in its config). Assume MQTT1 has a retained msg on topic "London/whatever" with message being "off". When I restart MQTT1, I get:
- On MQTT1, on topic "London/whatever", I get a message "off" with the retain bit set to true. This is what I would expect.
- On MQTT2, on topic "test/London/whatever", I get a message "off" with the retain bit set to false. This is NOT what I would expect. I would have expected the retain bit to be set to true because that message came from MQTT1 from a retain message.

Is the above expected behaviour or is that a bug? Or problem in my setup?

Thanks for the help.
Re: Mosquitto bridge and retain behaviour [message #1840987 is a reply to message #1840976] Thu, 29 April 2021 21:11 Go to previous messageGo to next message
Roger Light is currently offline Roger LightFriend
Messages: 90
Registered: September 2013
Member
When a normal client receives a PUBLISH message, the retained bit indicates whether the message was stale or fresh. A stale message has the retained bit set, and will only be received immediately after a SUBSCRIBE request was made. They mean "this publish was made at some point in the past, we don't know when". A fresh message occurs when a client already has a subscription in place and a message for that topic is received by the broker. If you want the retained bit to be propagated to the client you need to use the MQTT v5 "retain-as-published" option.

I hope that helps,

Roger
Re: Mosquitto bridge and retain behaviour [message #1840989 is a reply to message #1840987] Thu, 29 April 2021 21:28 Go to previous messageGo to next message
Florent Dupont is currently offline Florent DupontFriend
Messages: 5
Registered: April 2021
Junior Member
Thanks for the reply Roger, that sounds promising for my usecase indeed.

Would you be able to point me to some documentation for the "retain-as-published" option? I'm looking through Mosquitto documentation but cannot find something that looks like this (or anything else on Google actually).

All the clients used in my test are using protocol MQTTv5, as well as the bridge itself, so I presume the above option is not enabled by default.

Thanks,

Florent
Re: Mosquitto bridge and retain behaviour [message #1840990 is a reply to message #1840989] Thu, 29 April 2021 21:48 Go to previous message
Florent Dupont is currently offline Florent DupontFriend
Messages: 5
Registered: April 2021
Junior Member
Ah found it!

For whoever might be facing a similar problem:
I am using NodeRed for my project. In the MQTT nodes, there are flags that can be enabled. Among which I found "Keep retain flag of original publish" which is exactly what I needed to enable. Now the messages are propagated across the bridge with the retain flag still on.

Thanks again Roger.
Previous Topic:File descriptors leak
Next Topic:Dynamic Security Plugin - persisting in-memory to config file
Goto Forum:
  


Current Time: Tue Apr 16 03:54:01 GMT 2024

Powered by FUDForum. Page generated in 0.93256 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top