[zeromq-dev] using REQ in a real application

Christian Kamm kamm at incasoftware.de
Thu Jul 18 22:13:43 CEST 2013


On 07/18/2013 09:52 PM, Justin Karneges wrote:
> 2) What does the REQ socket do if it receives a message when it is not 
> in a "requesting" state? My hope is that it would read messages and 
> throw them away. If there's only exactly one read for every write, then 
> I can envision a situation where the alignment is off and every request 
> gets a wrongly matched response. Putting an id field on each 
> request/response will help detect this, but it wouldn't get you unstuck. 
> What can you say about this?

In the currently released versions, the recv() call on the REQ socket
will take a message from its pipes in a fair-queued way and hand that to
the application. That means if you make a REQ socket and someone
connects and sends a message to it, your next recv() will get that
message - even if it arrived before the send() call.

In zmq master that behavior has changed to drop all messages but the one
from the pipe that a request was sent to. And the send() will clear the
inbound message queues.

Christian



More information about the zeromq-dev mailing list