[zeromq-dev] using REQ in a real application

Justin Karneges justin at affinix.com
Thu Jul 18 21:52:49 CEST 2013


Hi,

I have a couple of concerns about using REQ.

1) In order to implement timeouts (which I'd think nearly every 
application should need), I use the following strategy:
   a) If I cannot write to the socket after enough time has passed, then 
I consider the request to have failed and I leave the socket in its 
current state.
   b) If I cannot read the response from the socket after enough time 
has passed, then I consider the request to have failed and I close and 
recreate the socket. I believe this socket resetting to be necessary so 
that the REQ state machine is willing to take writes again.

Does this seem like the right way to go about timeouts?

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?

Thanks.

Justin



More information about the zeromq-dev mailing list