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

unable to unsubscribe topics after client disconnects #49

Closed
mohkar opened this issue May 10, 2016 · 6 comments
Closed

unable to unsubscribe topics after client disconnects #49

mohkar opened this issue May 10, 2016 · 6 comments

Comments

@mohkar
Copy link

mohkar commented May 10, 2016

Hi Mcollina,

I want to unsubscribe to all the topics a client has subscribed to when he disconnects. After I reconnect I should not get messages of those topics unless I subscribe again. In order to achieve this on 'clientDisconnect' and 'clientError' events I am trying to explicitly unsubscribe to the topics. However, on these events I am getting 'subscriptions' object of the client as empty. But when I connect again, I am getting back all subscriptions on the 'subscriptions' object.

PS: I am using cleansession: false on client. QOS: 1

@mcollina
Copy link
Collaborator

Just use cleansession: true on the the client, that will do.

What code are you using to achieve this? It should work even if it was not intended to be used that way.

@mohkar
Copy link
Author

mohkar commented May 10, 2016

Yes, I am aware of that, but 'cleansession : true' will not hold messages if the client ungracefully disconnects which is something I would not want.
My main concern was, client object is not containing subscriptions in 'subscriptions' field of client on 'clientDisconnect' event.

@mcollina
Copy link
Collaborator

Those would already be gone, as with the 'clientDisconnect' event the client has no live subscriptions (that is used for live subscriptions). At the moment, that fied is not part of the public API and it is used internally.

I am fine in exposing this, but it would require a bit of work around doc and testing. The idea should be to have that flushed if the client is clean, but to maintain the state if the client is not clean.

BTW, to achieve what you want, it might be simpler to hook into the persistence and delete them from there directly.

If you want to send a PR, I will be happy to review.

@mohkar
Copy link
Author

mohkar commented May 12, 2016

Hi mcollina,
As you mentioned, I tried deleting subscriptions from redis manually. I did following:
On unsubscribing I deleted client key that is - 'client:sub:{client}' and
removed client entry from subscribed channels - 'sub:client:{subscription}'
However, the aedes is somehow still holding subscriptions and fetching me all the retained messages.

Could you please suggest me how to remove subscriptions completely from aedes.

@mcollina
Copy link
Collaborator

You must use the persistence api: https://github.com/mcollina/aedes-persistence
In particular, you need to use: https://github.com/mcollina/aedes-persistence#instancecleansubscriptionsclient-callbackerr-client

(all persistences implement the same API).

@mohkar
Copy link
Author

mohkar commented May 20, 2016

I tried using instancecleansubscription() method and I was able to completely remove clients subscriptions.
Thanks.

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

2 participants