eclipse / paho.mqtt.python

paho.mqtt.python
Other
2.17k stars 723 forks source link

Subscriptions just disappear #682

Closed Fischchen closed 1 year ago

Fischchen commented 1 year ago

I've noticed a big problem where subscriptions don't persist after server reboot

What I used:

paho-mqtt 1.6.1 RabbitMQ with MQTT Plugin

To reproduce:

Connect a publisher and a subscriber to any topic. Both are set to reconnect on failure.

"Reboot" the server, causing the both publisher and subscriber to disconnect, and later reconnect. Now any previous subscriptions are gone. As far as I know, this isn't mentioned in the Documentation.

Workaround

Put the subscribe you part of the code in the "On Connect" event

ralight commented 1 year ago

I would recommend putting your call to subscribe() in your on_connect() callback so that it is restored on reconnect. Alternatively, you should set clean_start to false and set a session-expiry-interval, for MQTT v5 clients, or set clean_session to false for MQTT v3.x clients.

I hope this helps.