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.

已提問 1 個月前檢視次數 147 次
1 個回答
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
專家
已回答 1 個月前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南