Open mayur-IG opened 3 months ago
Noticed that the disconnect was longer than KEEP_ALIVE_INTERVAL. maybe this caused the session to clear out.
No, whether the session is still present has nothing to do with the KEEP_ALIVE_INTERVAL.
Since you are setting clean_session
to false, you're telling the server to keep a persistent session for your client. Although you don't show the client construction, I assume that you're setting a unique Client ID, and reusing the same ID when you reconnect. The server tracks the session by Client ID.
With MQTT v5 there is a session expiry interval property that goes in the connect packet. This tells the server how long to keep the session after the client disconnects. You can tell it to keep the session active for an hour, day, week; whatever.
With MQTT v3 (which you appear to be using), the session is supposed to stay "forever". This was a mistake in the protocol design, because clients could connect, request a session, then disconnect and never be seen again. In which case the server accumulated all their messages forever. Because of this, many v3 servers have a configured expiry interval, after which they will discard the session.
In either case, when you connect, the server will tell you if it remembers your Client ID and has a "session present". You can get that from the server response to the connect call, as shown in a few examples, like: https://github.com/eclipse/paho.mqtt.cpp/blob/3631bce7e0bd74cc11a46410669ccd2e23b6caed/examples/async_consume.cpp#L72-L76
If the server does not have a session present for your client, then you do need to re-subscribe.
While using Async Client [paho-mqttpp3 paho-mqtt3as] with automatic_reconnect example connection options below:
There are some cases when the client disconnects and then reconnects. the application can handle these drops, so we do not crash out or throw any exception. The Issue is that we are able to publish messages but not receive any messages after the reconnection. I am not sure if there is a need to resubscribe to the topics again after this disconnect event [-3]