How to receive missed messages for 1 of N subscribers in ZeroMQ?

python, zeromq

Solution

If you are using a PUB-SUB connection (which it seems as if you are describing), then the quick answer is no. A Publishing socket drops messages instead of queuing them.

Even if you change your socket types to PUSH and PULL, you will still have issues. Yes the PUSH socket will block on non-received messages but because you will have another client connected, the message will be sent and thus will not block if one of the clients drop. With PUSH-PULL types, you're not able to 'subscribe' to certain messages as you're able to with PUB-SUB connections.

You can implement some logic to do what you're describing. Checkout zmq's guide (second bullet item) to see what they 'recommend' for a reliable connection. What is describing is essentially a method to keep track of which messages the client receives (incrementing id?) and a second connection that the client can then 'request that the missed messages be resent'.

The above section could also be implemented with a client to server 'heartbeat' that give the last message it received. The server checks this to make sure that the client isn't behind and re-publishes the messages if it is.

Problem

I want to use an AMPQ service in Python applications, but haven't worked with ZeroMQ. So I want to know if this can be done: - receiver1.py and receiver2.py subscribe to 'common_messages' from one host & port - receiver2.py crashes - sender sends a message - receiver1.py successfully receives it - receiver2.py is restarted - receiver2.py receives the message that was sent while it was absent Can this be done? Does ZeroMQ track what messages have been sent? If one subscribes after messages were sent, does ZMQ detect which old messages should to be received and which shouldn't be?

Original source