No you only get the subscription string on the XPUB the first time it is
made (unless you use ZMQ_XPUB_VERBOSE in which case you get repeat
subscriptions). Its just the message from the SUB socket you are receiving
thanks to XPUB (non PUB) exposing the subscription message.

If you want to maintain a "topic" list add a poll on the XPUB socket for
receive event, each time you get an event, receive from the socket and add
them to std::set<string> (or build your own set in C).


On Thu, Sep 20, 2018 at 10:11 PM Carol Rice <carol.ric...@gmail.com> wrote:

> Okay, I have something kind of working. I set up two different
> subscribers, each with a different filter topic. And one ZMQ_XPUB that I am
> sending and receiving on in a while loop.  I am now getting both "topics"
> in ascii hex form, but not as a list. I get one topic each iteration of the
> loop. Is there a way to receive ALL topics on a single iteration of the
> loop?
>
> On Thu, Sep 20, 2018 at 11:45 AM, James Harvey <
> jamesdillonhar...@gmail.com> wrote:
>
>> 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.ric...@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 <
>>> jamesdillonhar...@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.bocca...@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 <wallstp...@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.ric...@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@lists.zeromq.org
>>>>> > > > https://lists.zeromq.org/mailman/listinfo/zeromq-dev
>>>>> > >
>>>>> > > _______________________________________________
>>>>> > > zeromq-dev mailing list
>>>>> > > zeromq-dev@lists.zeromq.org
>>>>> > > https://lists.zeromq.org/mailman/listinfo/zeromq-dev
>>>>> > >
>>>>> >
>>>>> > _______________________________________________
>>>>> > zeromq-dev mailing list
>>>>> > zeromq-dev@lists.zeromq.org
>>>>> > https://lists.zeromq.org/mailman/listinfo/zeromq-dev
>>>>>
>>>>> --
>>>>> Kind regards,
>>>>> Luca Boccassi_______________________________________________
>>>>> zeromq-dev mailing list
>>>>> zeromq-dev@lists.zeromq.org
>>>>> https://lists.zeromq.org/mailman/listinfo/zeromq-dev
>>>>>
>>>>
>>>> _______________________________________________
>>>> zeromq-dev mailing list
>>>> zeromq-dev@lists.zeromq.org
>>>> https://lists.zeromq.org/mailman/listinfo/zeromq-dev
>>>>
>>>>
>>> _______________________________________________
>>> zeromq-dev mailing list
>>> zeromq-dev@lists.zeromq.org
>>> https://lists.zeromq.org/mailman/listinfo/zeromq-dev
>>>
>>
>> _______________________________________________
>> zeromq-dev mailing list
>> zeromq-dev@lists.zeromq.org
>> https://lists.zeromq.org/mailman/listinfo/zeromq-dev
>>
>>
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev@lists.zeromq.org
> https://lists.zeromq.org/mailman/listinfo/zeromq-dev
>
_______________________________________________
zeromq-dev mailing list
zeromq-dev@lists.zeromq.org
https://lists.zeromq.org/mailman/listinfo/zeromq-dev

Reply via email to