Persistent Sessions using the MQTT5

0

We are creating the connection using the MQTT5. we are looking for persist the session so when we will reconnect than the session resumes, subscriptions are reinstated, and unacknowledged subscribed messages received and stored prior to the reconnection are sent to the client. For that what will be the flag need to set while connecting and disconnecting. I have used (mqtt5.ClientSessionBehavior.RejoinAlways) while creating the connection and (mqtt5.ClientSessionBehavior.Clean) while reconnecting but it is not working.

Looking for support to achieve the above mentioned scenario.

asked a month ago137 views
1 Answer
0

When connecting the client, set the cleanSession flag to false to resume an existing session if one exists.

Set the sessionExpiryInterval to a non-zero value to persist the session for a duration even after disconnection.

On reconnecting, subscriptions, pending messages and QoS 1 messages will be reinstated from the previous session.

You can test this by publishing messages while the client is disconnected. On reconnecting, these messages should be received by the client.

Make sure the client ID remains the same across connections for the broker to identify and resume the correct session.

profile picture
EXPERT
answered a month ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions