[zeromq-dev] Multiple connects with a ZMQ_REQ socket appears not to work

Luca Boccassi luca.boccassi at gmail.com
Fri Feb 23 11:54:03 CET 2018

On Fri, 2018-02-23 at 04:57 +0000, Mark wrote:
> Hi all.
> According to http://api.zeromq.org/4-2:zmq-socket with a ZMQ_REQ
> socket I can connect to multiple endpoints and the semantics of
> zmq_send() are:
> 	"Each request sent is round-robined among all services, and
> 	each reply received is matched with the last issued request.
> 	If no services are available, then any send operation on the
> 	socket shall block until at least one service becomes
> 	available. The REQ socket shall not discard messages."
> IOWs the message should get to one of the connected endpoints
> eventually.
> But I'm not seeing that behavior. Rather, the message never arrives
> at
> any of the available endpoints.
> To demonstrate this I hacked up the hello world examples such that
> the
> client connects to two endpoints: the first nominates a port that
> nothing is listening on and the second nominates a port that the
> server is listening on. What I'm seeing is that the message exchange
> never occurs.
> I have attached both programs as they are minorly different from the
> examples on the zmq website.
> If I swap the connect order in the client such that the "up" server
> comes first, then the message exchange works. After further testing I
> deduce that attempting to exchange with second and subsequent connect
> endpoints are the problem.

That's because it's round-robin, and the connection is async - so it
will wait on the first server to respond, and it never does so it's
blocked there. Sounds like what you really want is "fail-over" - IE if
the first does not respond, try the second. That might work if you tune
the tcp reconnect options to have a small timeout, so that the pipe is
removed - by default it's quite large. Note sure it will work - try it.

Kind regards,
Luca Boccassi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: This is a digitally signed message part
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20180223/29057a92/attachment.sig>

More information about the zeromq-dev mailing list