[zeromq-dev] flushing messages on PULL socket before close()ing?

Michel Pelletier pelletier.michel at gmail.com
Fri May 11 15:53:23 CEST 2012

On Fri, May 11, 2012 at 4:51 AM, Alexander Voss <alexvoss.uk at gmail.com> wrote:
> Dear all,
> apologies in advance if I am missing something obvious here but I have
> a number of workers using a PULL socket to retrieve messages and I
> would like to be able to restart these workers as needed. The problem
> I am having is that the socket may have messages stored that I
> understand will be discarded when calling close() on the socket. The
> PUSH socket I am receiving from is the stable part that bind()s.
> So, is there a way to tell ZeroMQ to stop receiving new messages so I
> can process all that has already been received before calling close?
> Have I got the wrong end of the stick altogether?

At any time many messages may be in flight on the network.  Even if
your local receive socket has no data, there may still be messages
sitting in device buffers that will arrive imminently.  If you want to
turn off your sender for a specific receiver, you have to add that
instrumentation yourself.  I would suggest switching to a
ROUTER->DEALER pattern where the sender can tell a specific worker to
shutdown.  After that, send that worker no more messages.  The worker
will process messages up until it receives the shutdown message, and
then die.  No messages will be lost.  You can have the receiver
initiate the shutdown procedure by having a REP<-REQ pair where the
receiver asks the server to send it the shutdown message, when you get
that message, you know that receiver can safely shutdown.


> Cheers,
> Alex
> --
> Alex Voss
> Lecturer in Software Engineering
> School of Computer Science, University of St Andrews
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev

More information about the zeromq-dev mailing list