HiveMQ

Does MQTTv5 Session Expiry imply if the client does not get a message after fixed interval the client gets disconnected?

I got an understanding of why MQTTv5 Message Expiry which might help prevent retaining stale messages that might not reach the dedicated client. However I am not sure if I understand Session Expiry that well, however I feel like it is the mechanism I want.

Requirement

Is there a way for an MQTT client to disconnect from the broker gracefully after waiting for a fixed time interval and having not received a message on the subscribed topic?

Current Mechanisms that can be leveraged

I understand that an abrupt disconnect from a publishing client can lead to a Last Will and Testament Message / Topic triggering, which I can leverage in my application to successfully disconnect from the broker. Or the usage of keepAlive mechanism might be able to keep the session on-going between the broker and clients.

However in a situation where something goes haywire (firmware glitch) where the MQTT publisher still maintains the session but no data is published, how can the subscriber decide that after having waited for a fixed time interval it is time to disconnect from the broker since there is no data coming in on the subscribed topic?

Would something like setting:

sessionExpiry=300 and cleanStart=false on the subscriber actually be able to achieve this?

Hello Shan!

Does MQTTv5 Session Expiry imply if the client does not get a message after fixed interval the client gets disconnected?

No. The Session expiry interval defines the period of time that the broker stores the session information of that particular MQTT client after said client is disconnected. See: Session and Message Expiry Intervals - MQTT 5 Essentials Part 4

Is there a way for an MQTT client to disconnect from the broker gracefully after waiting for a fixed time interval and having not received a message on the subscribed topic?

MQTT does not provide such a mechanism out of the box, but you can implement this behaviour yourself.

Would something like setting:
sessionExpiry=300 and cleanStart=false on the subscriber actually be able to achieve this?

No. Those parameters define the MQTT session. See: Session and Message Expiry Intervals - MQTT 5 Essentials Part 4

Kind Regards,
Yannick

2 Likes