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

Is there a way to get event of a client getting disconnected from NATS server. #586

Closed
ritesh4302 opened this issue Sep 12, 2017 · 7 comments

Comments

@ritesh4302
Copy link

Do we get any event if any client gets disconneted from the broker, like in Mqtt we get to set a payload message for each client during client creation, and if the client is offline for a certain amount of time, then the server broadcast this payload message to all the connected clients.
Thanks in advance.

@tylertreat
Copy link
Contributor

See the disconnect handler in the Go client (and equivalent in other clients). https://godoc.org/github.com/nats-io/go-nats#Conn.SetDisconnectHandler

@ColinSullivan1
Copy link
Member

@ritesh4302

I believe you are speaking of the last will and testament functionality in MQTT. We do not have that today; by nature the NATS server maintains very little state about its clients. Could you describe your use case? There may be another solution.

@ritesh4302
Copy link
Author

@tylertreat @ColinSullivan1 thanks for your quick reply.

@ColinSullivan1
Our use case is such that, we have around a million devices connected to the NATS server and we have a web interface to monitor their connectivity status, so as of now we need to do a scheduled polling (every 30 seconds) on the end point (http://localhost:8222/connz) for all the devices and correspondingly update the database. Thus, we were wondering if we have any realtime event based mechanism which write updates on a given queue if a client is connected or disconnected.

@ColinSullivan1
Copy link
Member

@ritesh4302 , Thank you for sharing; I appreciate that. We don't have a realtime event notification for connection related events, although this has come up in the past. You are using the recommended approach with the features NATS provides today. Let's leave this open to track this idea.

@derekcollison
Copy link
Member

There is always a struggle between functionality at the system and application level to those desired in the product itself. NATS started with the thought that only the bare minimum needed to exist in NATS itself, and that applications and systems are able to easily implement the functionality they desire. This feels like one of those cases. Happy to help brainstorm a solution for you.

@pradeepreddy-iit
Copy link

@derekcollison , @ColinSullivan1
I think it is not difficult to implement since nats server knows when a client gets connected or disconnected, and its all about pushing that information to a configured subject. Correct me if I am wrong.
As I am new to Go Language, can you please tell me which file contains the code to manage the client connection/disconnection.

@ColinSullivan1
Copy link
Member

ColinSullivan1 commented Sep 18, 2017

Do you need any guarantees around the event that a client has been disconnected?

One option to entertain would be to look at taking what you've already done - polling the monitoring endpoints looking for differences - and then using that information to publish messages on specific event subjects. This would be a separate process outside of the NATS server(s), and could simplify other application code you might have.

If you wish to fork and implement this yourself, you'll probably find it is more involved than it looks up front. There is an old branch with functionality along these lines here, and the place to start looking would be here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants