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

subscribe / unsubscribe notification for PUB / SUB #1585

Closed
Sec42 opened this issue May 21, 2022 · 2 comments
Closed

subscribe / unsubscribe notification for PUB / SUB #1585

Sec42 opened this issue May 21, 2022 · 2 comments
Labels

Comments

@Sec42
Copy link

Sec42 commented May 21, 2022

Is your feature request related to a problem? Please describe.
I want to know if my pub socket has any subscribers at all. So it can stop it's work and avoid wasting resources when no one is listening

Describe the solution you'd like
Some way to get notified on subscribe/unsubscribe of clients. Extra niceness would be if you can get the topics they are subscribed to.

Describe alternatives you've considered
some way to get the current subscriber count && polling that would also work, I guess.

Additional context
Similar to this ZMQ XPUB feature: https://gist.github.com/minrk/2296266

@gdamore
Copy link
Contributor

gdamore commented May 21, 2022

It is possible to obtain the entire list of connected subscribers via pipe event hooks. (see nng_pipe_notify()).

However, for PUB sockets, it is not possible to know their subscriptions. That's because this pattern is very simply a receiver (subscriber) side filter. The publisher has no idea about subscriptions it just sends every message out that it is asked, to every subscriber. (Changing that behavior would require publisher side filtering, for which there is already a ticket filed. Publisher side filtering would require a complete rearchitecture of this pattern, and presents substantial design challenges (because of nng_device() type proxies). I still plan to do it someday, but I have to have enough cycles to spend on it, and $dayjob is keeping me otherwise occupied at present.

@Sec42
Copy link
Author

Sec42 commented May 22, 2022

With your hint I was able to find sock.add_post_pipe_connect_cb() and sock.add_post_pipe_remove_cb() in the python implementation which does take care of the subscriber tracking.

I was surprised to hear that filtering is client-side and not publisher-side. I did not expect this - it makes filtering a bit uninteresting for me.

I totally understand that you are busy with other things. I've subscribed to #1473 in the hopes this gets implemented at some time.

Thanks.

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

No branches or pull requests

2 participants