[zeromq-dev] Get a list of all topics

Bill Torpey wallstprog at gmail.com
Tue Sep 18 22:19:22 CEST 2018

Hi Carol:

ZeroMQ actually doesn’t have the concept of “topics”, at least in the way that term is used with other middlewares.

ZeroMQ does filtering on the prefix of a message, which is a bit of a different animal.  You can use that to create a topic-based addressing scheme similar to other middlewares, but it’s not an intrinsic part of ZeroMQ.

When a SUB socket connects to a PUB socket, the list of prefixes that the SUB wants to receive are sent to the PUB socket as part of the connection process.  Then, when the PUB socket wants to send a message to a SUB socket, it compares the list of prefixes it maintains for the SUB socket against the beginning of the message.  If there’s a match, the message is sent, otherwise it is discarded.  (That list can change over time as well, and the SUB sends any changes to all the PUBs that it is connected to).

If you follow that through, you can see that to get a list of all topics that are being subscribed to, you’d need to ask every subscriber and collect the results.  Publishers, on the other hand, are not associated with topics — the “topic” (actually filter) is associated with the SUB socket, although it is evaluated by the PUB socket when it has a message to send.  (The exception is when using a pgm: transport — since pgm is multicast, PUB sockets publish everything and it is the SUB socket that does the prefix matching when it receives a message). 

If you really need to know which “topics” exist on the network, you probably want to use XPUB/XSUB sockets (which expose the filters to the application), and perhaps also a central ZeroMQ broker.  The http://zguide.zeromq.org/page:all#The-Dynamic-Discovery-Problem chapter is a good starting point for learning about how that might work.

Hope this helps.


> On Sep 18, 2018, at 3:25 PM, Carol Rice <carol.rice08 at gmail.com> wrote:
> I know for pub/sub sockets, I can set the subscriber filter to an empty string and receive messages from all topics. 
> But I want to know if there is a way I can publish all available topics and receive a list of all the available topics to subscribe to?
> Thank you for your help.
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> https://lists.zeromq.org/mailman/listinfo/zeromq-dev

More information about the zeromq-dev mailing list