[zeromq-dev] Get a list of all topics
James Harvey
jamesdillonharvey at gmail.com
Thu Sep 20 19:45:17 CEST 2018
That’s actually just the libzmq wrapped in the cppzmq wrapper header (not
czmq). Just swap out each line for the C equivalent
On Thu, Sep 20, 2018 at 6:08 PM Carol Rice <carol.rice08 at gmail.com> wrote:
> James,
>
> I appreciate the example. I am having to use C and not C++. Do you have
> an example with the core C code? And not czmq, I am using capnproto-c with
> zmq. I could not get czmq to work with it.
>
> Thank you for your help
>
>
> On Wed, Sep 19, 2018 at 4:52 AM, James Harvey <jamesdillonharvey at gmail.com
> > wrote:
>
>> Also keep in mind the first byte of the message will be a 0/1 to give the
>> context.
>>
>> So something like this:
>>
>> zmq::message_t subscription;
>> pub_sock_->recv(&subscription);
>> char* data = (char*)subscription.data();
>>
>> // Subscriptions should start with 0x1 and unsubscriptions 0x0
>> if(*data != 0x1)
>> {
>> // unsubscribe
>> }
>> else
>> {
>> // subscribe
>> }
>>
>> std::string sub(data + 1, subscription.size() -1));
>>
>>
>>
>> On Wed, Sep 19, 2018 at 11:13 AM Luca Boccassi <luca.boccassi at gmail.com>
>> wrote:
>>
>>> If you call recv on an XPUB socket you'll get the subscriptions coming
>>> in - no need to use XSUB, will work with SUB too
>>>
>>> On Tue, 2018-09-18 at 17:03 -0600, Carol Rice wrote:
>>> > Thanks for the reply, Bill.
>>> >
>>> > I've read the zguide http://zguide.zeromq.org/page:
>>> > all#The-Dynamic-Discovery-Problem
>>> > and it appears this is exactly what xpub and xsub does:
>>> >
>>> > " We need XPUB and XSUB sockets because ZeroMQ does subscription
>>> > forwarding
>>> > from subscribers to publishers. XSUB and XPUB are exactly like SUB
>>> > and PUB
>>> > except they expose subscriptions as special messages. The proxy has
>>> > to
>>> > forward these subscription messages from subscriber side to publisher
>>> > side,
>>> > by reading them from the XPUB socket and writing them to the XSUB
>>> > socket.
>>> > This is the main use case for XSUB and XPUB."
>>> >
>>> > However, there is no example code for this is the zguide. Are there
>>> > any
>>> > examples in C code for using xpub/xsub for exposing subscriptions as
>>> > special messages? It sounds like this is what I'm looking for, to see
>>> > a
>>> > list of all the subscribed topics, or subscriptions.
>>> >
>>> > Carol
>>> >
>>> > On Tue, Sep 18, 2018 at 2:19 PM, Bill Torpey <wallstprog at gmail.com>
>>> > wrote:
>>> >
>>> > > 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.
>>> > >
>>> > > Bill
>>> > >
>>> > > > 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
>>> > >
>>> > > _______________________________________________
>>> > > zeromq-dev mailing list
>>> > > zeromq-dev at lists.zeromq.org
>>> > > https://lists.zeromq.org/mailman/listinfo/zeromq-dev
>>> > >
>>> >
>>> > _______________________________________________
>>> > zeromq-dev mailing list
>>> > zeromq-dev at lists.zeromq.org
>>> > https://lists.zeromq.org/mailman/listinfo/zeromq-dev
>>>
>>> --
>>> Kind regards,
>>> Luca Boccassi_______________________________________________
>>> zeromq-dev mailing list
>>> zeromq-dev at lists.zeromq.org
>>> https://lists.zeromq.org/mailman/listinfo/zeromq-dev
>>>
>>
>> _______________________________________________
>> zeromq-dev mailing list
>> zeromq-dev at lists.zeromq.org
>> https://lists.zeromq.org/mailman/listinfo/zeromq-dev
>>
>>
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> https://lists.zeromq.org/mailman/listinfo/zeromq-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20180920/89363874/attachment.htm>
More information about the zeromq-dev
mailing list