[nanomsg] Re: does nanomsg support multi producer in pub-sub mode?

  • From: "Dan Liu" <139250065@xxxxxx>
  • To: "nanomsg" <nanomsg@xxxxxxxxxxxxx>
  • Date: Wed, 30 Dec 2015 15:02:02 +0800

Do you mean a single consumer socket can connect different producer URLs at
same time ?




------------------ Original ------------------
From: "Garrett D'Amore";<garrett@xxxxxxxxxx>;
Date: Wed, Dec 30, 2015 02:49 PM
To: "nanomsg"<nanomsg@xxxxxxxxxxxxx>;

Subject: [nanomsg] Re: does nanomsg support multi producer in pub-sub mode?



If you have multiple producers the they will all need to call bind (with
different URLs). You can connect a single socket to multiple URLs.

Sent from my iPhone

On Dec 29, 2015, at 8:40 PM, Dan Liu <139250065@xxxxxx> wrote:


Dear Garrett:
According to your reply and other demos, I write below codes for multi
producer and consumer:


As any consumer which receive all topics:
int sock = nn_socket (AF_SP, NN_SUB);
nn_setsockopt (sock, NN_SUB, NN_SUB_SUBSCRIBE, "", 0);
nn_connect (sock, url);



As first producer which run bind:
int sock = nn_socket(AF_SP, NN_PUB);
nn_bind (sock, url);



As second producer without bind:
int sock = nn_socket (AF_SP, NN_PUB);
// nn_setsockopt (sock, NN_PUB, NN_SUB_SUBSCRIBE, "", 0);
nn_connect (sock, url);



Are these codes right? I'm not sure if nn_setsockopt should be run for second
producer which not run bind.


With best regards
Daniel


------------------ Original ------------------
From: "Garrett D'Amore";<garrett@xxxxxxxxxx>;
Date: Wed, Dec 30, 2015 08:14 AM
To: "nanomsg@xxxxxxxxxxxxx"<nanomsg@xxxxxxxxxxxxx>;

Subject: [nanomsg] Re: does nanomsg support multi producer in pub-sub mode?



1. Yes. One producer can publish to any topics ?? its just the ??prefix?? of
the message.2. Yes. See above.
3. Yes.
4. There is no such thing as ??broadcast?? in nanomsg. If you subscribe to a
zero length topic, you??ll get everything.
5. No. The roles are strictly defined ?? you have to be either SUB or PUB.
However, you can create a ??forwarder?? using nn_device().
6. I don??t have a demo handy at present, sorry, and its unlikely I??ll have
time to write one in the next day or so as I??m buried with other stuff. You
might want to look at some of the examples that are already present though.


- Garrett


On Tue, Dec 29, 2015 at 3:26 PM, ???????? <139250065@xxxxxx> wrote:
Dear Garrett:
Thanks for your kindly support! I have some questions more:
1. Does one producer socket can send message to multi topic?
2. Does one producer socket can broadcast message to all topic?
3. Does one comsumer socket can receive messages from multi topic?
4. Does one comsumer socket can receive broadcast message?
5. Can one socket be producer and comsumer socket at same time?
6. Would you please give some simple demo for multi producer, multi comsuer,
multi topic?


With best regards
Daniel




------------------ Original ------------------
From: "Garrett D'Amore";<garrett@xxxxxxxxxx>;
Date: Wed, Dec 30, 2015 02:11 AM
To: "nanomsg@xxxxxxxxxxxxx"<nanomsg@xxxxxxxxxxxxx>;

Subject: [nanomsg] Re: does nanomsg support multi producer in pub-sub mode?



Because nanomsg uses TCP, you can only have one process ??listening?? (i.e.
doing TCP accept.) This can indeed be the subscriber, as the role of
subscriber/publisher is orthogonal to the TCP client/server relationship. That
said, such a use case (having the subscriber be the one doing the
listen/bind/accept) is unconventional, but it will work.

On Tue, Dec 29, 2015 at 7:25 AM, ???????? <139250065@xxxxxx> wrote:
Dear Garrett:
Sorry! I didn't speak the question clearly. My real question is: Can multi
process(producer) post messages to same url(same message queue)? If can, should
each producer run nn_bind function?
With best regards
Daniel




------------------ ???????? ------------------
??????: "Garrett D'Amore";<garrett@xxxxxxxxxx>;
????????: 2015??12??29??(??????) ????11:15
??????: "nanomsg"<nanomsg@xxxxxxxxxxxxx>;

????: [nanomsg] Re: does nanomsg support multi producer in pub-sub mode?



Yes. You can connect to multiple publishers and since the subscription is
merely a client side filter you will see the appropriate messages from both
subscribers.

Sent from my iPhone

On Dec 29, 2015, at 2:19 AM, ???????? <139250065@xxxxxx> wrote:

Dear all:
does nanomsg support multi producer in pub-sub mode?

with best regards
daniel

Other related posts: