MQTT Clean session

A.Alqadomi picture A.Alqadomi · Mar 16, 2016 · Viewed 7.8k times · Source

Assume that I connected to the broker with "clean session=false" and started receiving events, in case of disconnection ideally my application will still receive data on connection. But if the application is crashed I want to have a fresh start and clear my session.

Can I clear my session on the MQTT broker and have a fresh start?

From the documentation I concluded that if I wanted to do that I would need to do the following:

  1. application start

  2. connect using "clean session=true" // this will cause any current session to be removed along with its data

  3. every thing related to the session is purged from server

  4. disconnect

  5. connect using "clean session=false" and start getting the data.

I got the idea from http://www.hivemq.com/blog/mqtt-essentials-part-3-client-broker-connection-establishment

"If clean session is set to true, the broker won’t store anything for the client and will also purge all information from a previous persistent session."

Is this the correct way to clear a previous session?

Answer

ralight picture ralight · Mar 16, 2016

Yes, that is the only way to clear a session for a client.