[zeromq-dev] Many to many

Whitney Jackson whjackson at gmail.com
Sun Feb 17 08:48:59 CET 2013


> I'm guessing the subs cannot connect to many?

Guess again :) Here's a python example:

# start sub.py
import zmq
c = zmq.Context()
s = c.socket(zmq.SUB)
s.setsockopt(zmq.SUBSCRIBE, '')
s.connect('ipc://ep1')
s.connect('ipc://ep2')

while True:
    m = s.recv()
    print m
    print ''
# end sub.py

# start pub.py
import time
import zmq

c = zmq.Context()
s = c.socket(zmq.PUB)
s.bind('ipc://ep1')
s.bind('ipc://ep2')

while True:
    print 'hi'
    s.send('hi')
    time.sleep(1)
# end pub.py

sub.py will print two 'hi's every second because it received one on
ipc://ep1 and another on ipc://ep2.



On Sun, Feb 17, 2013 at 1:22 AM, Lee Sylvester <lee.sylvester at gmail.com>wrote:

> Thank you for your reply, Witney, but I need it the other way. I need a
> sub socket to be connected to multiple pub endpoints... This is because
> every instance will have a single publisher, telling all who is interested
> about events, but that same service will want to list to an arbitrary
> number of other services for their events. Essentially, I'd be forming a
> type of mesh, where each service has  two endpoint (pub and sub) and all
> connect to all. I knew pub could connect to many, as it binds, but I'm
> guessing the subs cannot connect to many?
>
> Thanks loads,
> Lee
>
> Sent from my iPhone
>
> On 17 Feb 2013, at 05:18, Whitney Jackson <whjackson at gmail.com> wrote:
>
> > Is it possible for a sub socket to bind to multiple pub sockets?
>
> Yes. You can call bind and/or connect on a socket as many times at you
> like.
>
> > If so, where is there an example of this?
>
> Here's an example from the guide where a pub socket is bound to multiple
> endpoints:
>
> http://zguide.zeromq.org/page:all#Getting-the-Message-Out
>
> If you connect a sub socket to multiple endpoints then it gets a message
> whenever any of the publishers to which it's connected send.
>
>
>
> On Sat, Feb 16, 2013 at 4:18 PM, Lee Sylvester <lee.sylvester at gmail.com>wrote:
>
>> Hey guys,
>>
>> So, I want to do a many to many pubsub.  I already have a discovery
>> mechanism and logging, but what I need is for a service to bind to a pub
>> socket and subscribe to a set list of instances of itself on the server and
>> other servers. The Zyre framework, although awesome, seems a little large
>> for my needs as I already have a number of the features it supplies built
>> in to my framework. Is it possible for a sub socket to bind to multiple pub
>> sockets?  If so, where is there an example of this? Can I also add a pub
>> socket to listen to when all is already running?
>>
>> Thanks,
>> Lee
>>
>>
>> _______________________________________________
>> zeromq-dev mailing list
>> zeromq-dev at lists.zeromq.org
>> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>>
>
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>
>
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20130217/62c1a616/attachment.html>


More information about the zeromq-dev mailing list