-
-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changed default to CleanSession(false) to preserve previous subscriptions #18
base: master
Are you sure you want to change the base?
Conversation
Does it subscribe again using the exact same channel string, including options, like "last"? The problem I have with this flag, is that it seems to imply things on the broker side, and the Emitter broker does not implement anything regarding this on its side. |
Good question! The paho documentation says that it "does not tell the server to clear the session when you reconnect", so the idea is that the MQTT server already knows your session state (based on your UUID in the case of emitter-go), and is willing to resume it. Whether this means |
Yes, that's what I wrote in the edited version of my answer, just before you wrote yours. |
That is true, and I am on the fence here as well. Personally, I've moved my The main problem I have with the current implementation is that it's basically impossible to guarantee that you are ever subscribed. A microsecond after you subscribe, there could be a network interruption that triggers an auto-reconnection, then you're connected but not subscribed anymore. Currently I'm using emitter across about 40 servers in three continents, and they never fail to find a way to disconnect, even though I've spread emitter cluster members around the earth to reduce latency. |
I don't see it... If you set the OnConnect handler before sending your first connection request, and only subscribe in this handler: how then could you "miss" the subscription? |
Sorry, I was referring to my code before I used OnConnect. Now it is working properly. |
Shouldn't some of this be in the documentation, so every person who comes along doesn't have to re-discover it for themselves? |
Definitely, although if this is just a documentation issue, we'll need to ensure that basically every code example uses this paradigm. |
Also, it's probably still nice to be able to set |
IMHO, it should be set to false by default. That seems like the "least surprise" option to me. But in any event it needs to be documented. |
I haven't tested the clean session set to false in Go, but I just did a quick test with the Python version of Paho MQTT, and it doesn't re-subscribes. Which is in consistent with what I read here about the Python lib .
And about MQTT in general, on the IBM knowledge center :
To me, it's clear everything is supposed to happen on the broker side. And the fact that the Go library takes upon itself to re-subscribe is a exceptional behavior. It does not follow the rule. I think that the best we could do is to add to every emitter lib some "resubscribe" parameter, and implement the behavior independent of the MQTT's clean session flag. |
Thanks for the response!
Agreed that we probably don't want to resubscribe explicitly in the emitter wrapper. The argument for I'm understanding you correctly, you agree that the default behavior is that the user must explicitly re-subscribe to their channel(s) in It seems like this PR is still valuable, but I should change the default back to |
Ok. Let's do this. I'll merge the pull request then... |
Ok, sounds good. I'll get it changed and let you know. |
9cfed38
to
444fa0b
Compare
@Florimond @MichaelHipp I've updated the PR to maintain the current options and left the ability for users to set What do you think? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While all information given about cleansession is true for MQTT brokers, it should be clarified that Emitter does not implement these behaviors, and that that's the underlying go MQTT lib that takes upon itself to resubscribe. Messages however won't be sent unless requested upon resubscription (with last or what I'm going to add now "WithFrom" and "WithUntil").
My understanding is that all MQTT clients resubscribe like this since it's a core feature of MQTT. I did not think it was go-specific. |
2bf1659
to
86bf0fa
Compare
See issue #17 : upon reconnection, all existing subscriptions are lost. The two ways I've found to fix this are to set
CleanSession(false)
in the MQTT client, or to explicitly resubscribe to all channels in theOnConnect()
handler. I don't see a good reason for the session to be cleaned during a reconnection, so I've added this PR to change the default of MQTTCleanSession
fromtrue
tofalse
. I've also added an option to allow the user to change it back withWithCleanSession()
.Related discussion and docs:
eclipse-paho/paho.mqtt.golang#22
https://godoc.org/github.com/eclipse/paho.mqtt.golang#ClientOptions.SetCleanSession