[zeromq-dev] REQ to many REP.

Goswin von Brederlow goswin-v-b at web.de
Thu Jun 26 10:08:13 CEST 2014

On Mon, Jun 23, 2014 at 09:24:56PM +0100, Riskybiz wrote:
> I'd like to set up a 0MQ  REQ-REP arrangement where there are many REP
> sockets connected to just one REQ socket.  The actual number of REP sockets
> is unknown at design-time; however at run-time a list of the port addresses
> will be provided to the code running the REQ socket.
> What I'd like is that, somehow, the code running the solitary REQ socket
> will loop through the list of port addresses and connect to the multiple REP
> sockets as they bind and become available.  Subsequently the REQ socket
> would work with (poll??) the established connections to send and receive
> messages as necessary.

It would be simpler to bind the REQ socket and connect the REP sockets.

Send and receive just works and since you only have one socket there
is no need to poll.
> It's the first time I've tried this.  Looking at the zmq_poll reference in
> the manual http://api.zeromq.org/3-2:zmq-poll it's unclear to me whether I
> can handle variable number of connections in an iterative manner.  For
> example in: http://zguide.zeromq.org/cpp:mspoller the poll set is hard
> coded.

Poll handles sockets. Connects are handled transparently internally
according to the strategies listed in the docs for each socket type.

> Another question is can a REQ socket handle multiple connections?  How best
> could a message be routed to the desired destination REP socket?  Is some
> more advanced pattern necessary here ROUTER, BROKER??

REQ has a round-robin outgoing strategy. So you can't route any
message, libzmq will pick one for you.
> What I'm trying to achieve is a REQ-REP flow to act as a command/control
> layer which will coordinate a PUSH-PULL socket pair. There will be a
> run-time flexible number of PUSH sockets but always just one PULL socket.
> Is anyone able to offer any guidance to clear my muddy thoughts on how to
> make this work? Am coding in C++.

Start by describing what you want to do. Not the solution you think is
> With thanks,
> Riskybiz.


More information about the zeromq-dev mailing list