[zeromq-dev] ZMQ REQ client with multiple socket servers blocked when one server is down?

Luca Boccassi luca.boccassi at gmail.com
Mon Jan 2 14:01:42 CET 2017


REQ-REP is intentionally very strict. The REQ socket will round-robin
among all endpoints.

Given an internal pipe is created immediately and synchronously by the
library when you call zmq_connect, it will block if the other end is not
connected yet.

To override this behaviour, set the ZMQ_IMMEDIATE socket option before
the connect() calls. This will result in the unconnected endpoints being
"ignored" until they are connected.

socket.setsockopt(zmq.IMMEDIATE, 1)

On Sat, 2016-12-31 at 14:29 +0100, D.A. Vaughn wrote:
> In the example below taken from Nicholas Piel's ZMQ tutorial, a client
> makes connections to socket 5000 and 6000. My question is, suppose
> there are two separate servers, one that handles port 5000 messages
> and one that handles 6000?
>  
> What happens if the server listening to port 5000 is down? It appears
> to me this client below is blocked even though one of its servers is
> available.
>  
> Regards
>  
> David
>  
> import zmq
> context = zmq.Context()
> socket = context.socket(zmq.REQ)
> socket.connect("tcp://127.0.0.1:5000")
> socket.connect("tcp://127.0.0.1:6000")
>  
> for i in range(10):
>     msg = "msg %s" % i
>     socket.send(msg)
>     print "Sending", msg
>     msg_in = socket.recv()
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> https://lists.zeromq.org/mailman/listinfo/zeromq-dev


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20170102/c073da64/attachment.sig>


More information about the zeromq-dev mailing list