[zeromq-dev] push/pull and multiple workers

andrea crotti andrea.crotti.0 at gmail.com
Fri Aug 17 15:44:11 CEST 2012


2012/8/17 Pedro Melo <melo at simplicidade.org>

> Hi,
>
> On Fri, Aug 17, 2012 at 2:17 PM, andrea crotti
> <andrea.crotti.0 at gmail.com> wrote:
> >> In that situation then you want to use a forwarder device. The forwarder
> >> device binds to an incoming and an outgoing port. The publisher(s)
> connect
> >> to the incoming port and the subscriber(s) connect to the outgoing port
> of
> >> the device.
> >>
> >> All messages flow through the device to the subscribers. By using the
> >> intermediate device, the subscribers do *not* need to know about every
> >> possible publisher. It's a very neat and tidy solution.
> >
> > You mean something like this right? http://zguide.zeromq.org/py:wuproxy
>
> No, something like this:
>
> http://api.zeromq.org/3-2:zmq-device
>
>
Thanks I got it working:
def start_forwarder():
    context = zmq.Context()
    frontend = context.socket(zmq.SUB)
    frontend.connect(TASK_FRONT)
    frontend.setsockopt(zmq.SUBSCRIBE, '')
    backend = context.socket(zmq.PUB)
    backend.bind(TASK_BACK)

    forw = zmq.device(zmq.FORWARDER, frontend, backend)

And is it the same thing as this right?

def start_proxy():
    context = zmq.Context()
    frontend = context.socket(zmq.SUB)
    frontend.connect(TASK_FRONT)
    frontend.setsockopt(zmq.SUBSCRIBE, '')
    backend = context.socket(zmq.PUB)
    backend.bind(TASK_BACK)

    while True:
        msg = frontend.recv()
        more = frontend.getsockopt(zmq.RCVMORE)
        if more:
            backend.send(msg, zmq.SNDMORE)
        else:
            backend.send(msg)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20120817/5378bf84/attachment.htm>


More information about the zeromq-dev mailing list