Skip to content
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

Should send message to client on (re-)connect or handle re-subscribes also #10

Closed
Hades32 opened this issue May 15, 2015 · 5 comments
Closed
Assignees
Milestone

Comments

@Hades32
Copy link

Hades32 commented May 15, 2015

When the MQTT connection is broken and re-established, the subscriptions are gone. (Just like expected) This means that the client as to re-subscribe to his topics. But as there is no (info) message for this event, there is no option to do so.

My proposal is to have a handle_info(connected, State = #state{mqttc = C, seq = I}) function which is always called after connack, no matter if it is the first connect or a reconnect. Thus this method can be a central point for managing subscriptions.

Alternatively the client could remember the subscriptions and restore them after a reconnect. But I don't think this would be a good idea: Many clients use last-will messages which trigger some stuff and then use on-connected callbacks to indicate to the application that they have regained connection. Therefore a manual connected handling would be preferable IMHO.

@Hades32
Copy link
Author

Hades32 commented May 16, 2015

I implemented some crude hack, to have some kind of connection listener: Hades32@e7cc33a (It's my first lines of Erlang, so don't take it to seriuosly ;) ) It's just to illustrate what I'm trying to have.

emqplus pushed a commit that referenced this issue May 18, 2015
@emqplus
Copy link
Contributor

emqplus commented May 18, 2015

hi Martin, you did right:) The emqttc should emit 'connected', 'disconnected' event to the user process.

I replace the connection_listener with parent process. Please pull the latest commit to check if it works for your requirements.

@emqplus
Copy link
Contributor

emqplus commented May 18, 2015

Example code: 'emqttc/examples/gen_server/src/gen_server_example.erl'

@emqplus emqplus added this to the 0.4.0 milestone May 18, 2015
@emqplus emqplus self-assigned this May 18, 2015
@emqplus
Copy link
Contributor

emqplus commented May 22, 2015

Added a 'auto_resub' flag.

{ok, C} = emqttc:start_link([{client_id, <<"testClient">>}, auto_resub, {reconnect, 3}]).

emqttc client will resubscribe topics automatically when reconnected if this flag is set.

@Hades32
Copy link
Author

Hades32 commented May 22, 2015

Great solution! Thanks!

@Hades32 Hades32 closed this as completed May 22, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants