Retrieving subscriber count using zeromq PUB/SUB sockets

后端 未结 3 2189
温柔的废话
温柔的废话 2021-02-19 11:41

Is it possible to get the total count of subscribers from a PUB socket in zeromq?

Thanks!

3条回答
  •  盖世英雄少女心
    2021-02-19 11:55

    Yes, but unfortunately not via any simple property or method.

    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.

提交回复
热议问题