使用 zeromq PUB/SUB 套接字检索订阅者计数 [英] Retrieving subscriber count using zeromq PUB/SUB sockets
问题描述
是否可以从 zeromq 中的 PUB 套接字获取订阅者总数?
Is it possible to get the total count of subscribers from a PUB socket in zeromq?
谢谢!
推荐答案
是的,但不幸的是不是通过任何简单的属性或方法.
Yes, but unfortunately not via any simple property or method.
您需要使用 zmq_socket_monitor() 函数来连接一个inproc
服务套接字到您要观察的主套接字.从那里您可以收听有关连接/断开连接的事件并保持自己的订阅者数量.不过,这可能不是一项微不足道的任务,因为(至少对我而言)似乎有点难以知道何时考虑订阅者(或任何远程连接)启动/关闭(关闭/断开连接/重试等).你将不得不玩一会儿.
You need to use the zmq_socket_monitor() function to connect an inproc
service socket to the main socket you want to observe. From there you can listen to events regarding connect/disconnect and keep your own count of subscribers. It may not be a trivial task though, since it seems (to me at least) a bit hard to know when to consider a subscriber (or any remote connection) to be up/down (closed/disconnected/retry etc.). You will have to play around a bit.
该链接包括示例和活动说明.
The link includes samples and event descriptions.
这篇关于使用 zeromq PUB/SUB 套接字检索订阅者计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!