RuuviBridge icon indicating copy to clipboard operation
RuuviBridge copied to clipboard

Bridge does not resubscribe to MQTT topic on broker restart

Open Leppunen opened this issue 2 years ago • 2 comments

After running the bridge/gateway combination for some time, i have noticed that when my MQTT broker restarts due to updates and whatnot, the bridge does not resubscribe to the ruuvi/+ topic upon reconnecting to the broker, requiring a full process restart to get back running again. I have experienced this with both Mosquitto and EMQX as the broker implementations.

Leppunen avatar Mar 04 '24 09:03 Leppunen

RuuviBridge uses persistent sessions (in order to be able to catch messages sent while RuuviBridge itself is not connected, for example due to restarting/updating it, connectivity issues, etc) which also means resubscribing is not necessary (and in fact doing so would cause a duplicate subscription) since the MQTT server will remember the subscriptions of a persistent session by the MQTT spec

For mosquitto, you should check that persistence is enabled in the config, and that persistence_location points to a directory that is writable (and not lost), see: https://mosquitto.org/man/mosquitto-conf-5.html

For EMQX I have no experience of using, but assuming it supports/follows the MQTT spec, it should have a similar mechanism to deal with MQTT clients that connect with the clean session flag set to false (=persistent session)

Scrin avatar Mar 04 '24 12:03 Scrin

Indeed, it looks like i didn't have persistence configured on my brokers. i'm quite new to understanding mqtt internals so i wasn't aware of that. i configured persistence on both brokers and the connections survive broker restarts now. Thanks for pointing me to a correct direction

Leppunen avatar Mar 04 '24 13:03 Leppunen