hivemq/hivemq-mqtt-client

How to close all topic-subscription on the client?

georrge1994 opened this issue · 2 comments

For example: I have a client holder. I would like to close the connection and unsubscribe from all topic. If I just disconnect cient, the subscriptions will continue work with auto-reconnection -> that' wrong. I want to close all connections. Do not see the simple way for it. The single possible way only If I put all topic-subscriptions to the list and unsubscribe them in the disconnection moment. I don't want ot make my code dirty. How to prevent it?

Hi @georrge1994 - You can control this behaviour with SessionExpiryInterval and CleanSession. Some in depth explanation of these options are described in this blog post.

If you reconnect with cleanSession=true, all previous session state is discarded (including subscriptions).

On connect and disconnect, you can control how long the session state will persist for with sessionExpiryInterval.

I believe these are the options you are looking for. Let us know if this helps.