Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ZMQ PUSHer with no PULLer

Tags:

zeromq

I have a ZeroMQ network consisting of a PUSHer and multiple PULLers. The problem is that the number of pullers is unknown and, in certain cases, it can be 0. When the latter happens, socket.send(msg) never seems to return. If I remember well, this doesn't happen with PUB/SUB sockets.

Is there any way to avoid pushing packets when there is no puller on the other side of the pipe?

Thanks!

like image 998
dberenguer Avatar asked Dec 15 '22 16:12

dberenguer


1 Answers

You can avoid blocking in several ways:

  • Use zmq_poll to check when the PUSH socket is ready for output, and only send when it is ready.
  • Use non-blocking sends (ZMQ_DONTWAIT on zmq_msg_send method)
  • Set a send timeout to zero on the socket (ZMQ_SNDTIMEO socket option) and handle the error return when the send times out
  • Use a different socket pattern, e.g. ROUTER-DEALER with more explicit signalling from clients to server
like image 78
Pieter Hintjens Avatar answered Mar 04 '23 05:03

Pieter Hintjens