MQTTnet icon indicating copy to clipboard operation
MQTTnet copied to clipboard

Managed client clean session support

Open rcollada opened this issue 6 years ago • 10 comments

Hi, I just would like to understand the rational behind the fact that the Managed client does not support Clean Session. Even if I implement my own managed client, because I need to recover the session I wonder if I'm missing something there. Regards.

rcollada avatar Dec 11 '18 14:12 rcollada

Hi, the problem is that it requires some more complex subscription handling.

Lets say you just pass true via connecting. Then the managed client will still subscribe to all topics automatically (like at the moment). But then he will get all retained messages for that topic. If the session exists the subscriptions also exist at the server. So there is no need from the client to do this. But if the client ignores this fact he subscribes and then receives all retained messages.

This is not a problem in general but some users may don't want this. Other may accept it. So it should be configurable in my opinion or supported out of the box. So this means the subscriptions must be handled including a flag saying "this subscription is approved by the server". It has to be set only after a successful SubAck. Then after a reconnect the client must inspect the ConnectAck if the session is really existing. If the session is still new all subscriptions must be invalidated and subscribed again.

But if this flow works well it can happen that a client ID is used twice (by accident). If the second client creates a new session with other subscriptions the original client may find another session after taking over the connection and thinks that the session exists (and thus is his one). So the client will keep a broken set of subscriptions.

I hope this gives you a quick overview about the reasons which causes the not supported existing sesions (yet).

Best regards Christian

chkr1011 avatar Dec 11 '18 19:12 chkr1011

Do have any clue when this will be supported?

kmaesdillen avatar Dec 12 '18 10:12 kmaesdillen

At the moment this is on low priority. I am mostly busy with MQTT v5 support. After this is done I will prepare some other tasks. But it is still possible to use the core Client and build a managed client with the exact required features.

chkr1011 avatar Dec 12 '18 19:12 chkr1011

Hi, this is exactly what I need. Nevertheless, for me it's ok to just set cleansession to false, I don't use retain messages on the same topic. So subscribing again will not result in unwanted behaviour I think. I'll try that.

RainerMueller82 avatar Dec 20 '18 12:12 RainerMueller82

Is this still a valid feature request?

SeppPenner avatar Jun 28 '19 16:06 SeppPenner

I downloaded the managed client and modified a little bit to support clean session false, and it have been working perfectly in a small prod server. It would be great if the feature could be included in the nugget package but in the mean time if you need a workaround that's what you can do.

rcollada avatar Jun 28 '19 16:06 rcollada

I also have this topic on my list but had no time to start it. So please be patient and wait some more time :smile:

chkr1011 avatar Jun 28 '19 17:06 chkr1011

@chkr1011 I'd like to use ManagedMqttClient with persisted sessions. I see that this PR has been merged already. Unfortunately 3.0.9-rc1 does not have it. Would it be possible to publish an rc2 package?

t03apt avatar Apr 03 '20 10:04 t03apt

I will release 3.0.9-rc2 soon. Hopefully this weekend.

chkr1011 avatar Apr 04 '20 11:04 chkr1011

@chkr1011 This is already done, isn't it?

SeppPenner avatar Jun 14 '22 06:06 SeppPenner