Note that there are some explanatory texts on larger screens.

plurals
  1. POHow should a ZeroMQ worker safely "hang up"?
    primarykey
    data
    text
    <p>I started using ZeroMQ this week, and when using the Request-Response pattern I am not sure how to have a worker safely "hang up" and close his socket without possibly dropping a message and causing the customer who sent that message to never get a response. Imagine a worker written in Python who looks something like this:</p> <pre><code>import zmq c = zmq.Context() s = c.socket(zmq.REP) s.connect('tcp://127.0.0.1:9999') while i in range(8): s.recv() s.send('reply') s.close() </code></pre> <p>I have been doing experiments and have found that a customer at <code>127.0.0.1:9999</code> of socket type <code>zmq.REQ</code> who makes a fair-queued request just might have the misfortune of having the fair-queuing algorithm choose the above worker right after the worker has done its last <code>send()</code> but before it runs the following <code>close()</code> method. In that case, it seems that the request is received and buffered by the ØMQ stack in the worker process, and that the request is then lost when <code>close()</code> throws out everything associated with the socket.</p> <p>How can a worker detach "safely" — is there any way to signal "I don't want messages anymore", then (a) loop over any final messages that have arrived during transmission of the signal, (b) generate their replies, and then (c) execute <code>close()</code> with the guarantee that no messages are being thrown away?</p> <p><strong>Edit:</strong> I suppose the raw state that I would want to enter is a "half-closed" state, where no further requests could be received — and the sender would know that — but where the return path is still open so that I can check my incoming buffer for one last arrived message and respond to it if there is one sitting in the buffer.</p> <p><strong>Edit:</strong> In response to a good question, corrected the description to make the number of waiting messages plural, as there could be many connections waiting on replies.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload