[zeromq-dev] ROUTER-DEALER missing connects/messages.
Chuck Remes
lists at chuckremes.com
Tue Sep 25 17:30:02 CEST 2012
On Sep 25, 2012, at 10:05 AM, Dowd, Brian wrote:
> HI Michel,
> Yes it is a multi-part message on the send side, however the first part is just the identity/destination/address details
> (i.e. client-1/client-2 etc), and the setIdentity() call in the "Client" side of things associates thw two so that when the
> "client-1" is set in the first part the ZMQ layer knows to send that message to the "Client" that connected with identity
> "client-1" .... Also, just in case I did double check the rtdealer.c and it behaves exactly equivalently in that it does not
> loop as you suggest, but does it the same way as my java example more or less, I imagine looping woudl make sense
> when you are not using ROUTER/DEALER and do not know in advance how many parts there are ...
>
> I dont believe it is the issue here.
I believe your issue is due to a race condition during startup. Simply put, when the ROUTER socket binds to an endpoint it does not actually create an outgoing queue *until* a client connects to it. So any messages written to the ROUTER socket will be dropped at first. Take a look at its behavior as documented in the zmq_socket man page. This dropping behavior (when there are no connected clients) may not be clear from that man page, but we do have it in the FAQ.
http://www.zeromq.org/area:faq
Putting a "sleep" in your server corrects this behavior because it gives the client threads a chance to start up and actually connect to the bound endpoint. When the ROUTER socket sees a peer, it creates an outgoing queue for it. Any subsequent writes to that ROUTER socket can now be placed in the queue (subject to any HWM limits).
To solve this, I recommend changing your client. Instead of each client thread creating its own context and socket, your main thread should create a single context and spawn all of the sockets that you will ever need, connect them, and then sleep briefly. Pass this connected socket to your thread constructor.
Also, anyone using ROUTER/DEALER sockets should read this write-up: http://www.zeromq.org/tutorials:dealer-and-router
cr
More information about the zeromq-dev
mailing list