hivemq / hivemq-mqtt-client

HiveMQ MQTT Client is an MQTT 5.0 and MQTT 3.1.1 compatible and feature-rich high-performance Java client library with different API flavours and backpressure support
https://hivemq.github.io/hivemq-mqtt-client/
Apache License 2.0
864 stars 162 forks source link

How could I remove all subscribed topics? #470

Closed denebchorny closed 3 years ago

denebchorny commented 3 years ago

Problem or use case

When a user enters the app they dynamically subscribe to some topics. When he closes the session of the app I would like to delete all these topics.

By the time the user closes the session I do not know what the subscribed topics are.

And very important, I am using clean session to false with a duration of 7200 seconds. So if at the time of closing the session I do not clear the topics, then, if the user should no longer have access to a topic and log in again, we will have a security problem.

Preferred solution or suggestions

A method just to notify broker: hey, delete all subscribed topics

MicWalter commented 3 years ago

Hi @denebchorny,

why do you need a persistent session when you want to delete all subscriptions anyway? Or are the user generated subscriptions only a subset of all subscriptions?

Greetings, Michael from the HiveMQ team

pascaldekloe commented 3 years ago

The MQTT protocol does not provide such functionality. https://groups.google.com/g/mqtt/c/VfED9cMPMvU/m/pCuNS6BEo3gJ

It sounds like you have an architectural problem, as there is no way to ensure execution before closing the session. The connection may be interrupted by network failure for example. ;-)

SgtSilvio commented 3 years ago

I will close this issue because of inactivity and because the best answer for the current information is to use the right session expiry. Please feel free to comment if you still think this question is unanswered.