ZMQ PUSHer without PULLer

I have a ZeroMQ network consisting of PUSHer and several PULLers. The problem is that the number of pullers is unknown, and in some cases it can be 0. When the latter happens, socket.send (msg) never returns. If I remember well, this does not happen with PUB / SUB sockets.

Is there a way to avoid pressing packages when there is no puller on the other side of the pipe?

Thanks!

+4
source share
2 answers

You can avoid blocking in several ways:

  • Use zmq_poll to verify that the PUSH socket is ready to exit and only send it when it is ready.
  • Use non-blocking items (ZMQ_DONTWAIT using the zmq_msg_send method)
  • Set the send timeout to zero on the socket (socket option ZMQ_SNDTIMEO) and process the error return when the send time
  • Use a different socket pattern, for example. ROUTER-DEALER with more explicit signaling from clients to the server.
+8
source

Short answer: PUSH / PULL and PUB / SUB have different semantics.

PUSH / PULL distributes the pressed messages between the pullers. You use this when you want to deploy and make sure your materials are processed. If no one listens, it blocks.

PUB / SUB broadcasts published messages to all subscribers. If no one is listening, messages are lost.

It seems to me that PUB / SUB is more suitable for your use case. The phantom with lost messages makes no sense in the end.

+4
source

All Articles