Matt
Matt

Reputation: 7254

ZeroMQ, messages sent by DEALER -> disconnected ROUTER are not discarded. How to change that?

I have a DEALER socket that connects to a ROUTER socket, however , the ROUTER socket may at times unBind and re-bind to the same port (due to the application shutting down and re-start that binds the socket).

How can I ensure that any and all messages sent by the DEALER in the meantime will be discarded/dropped? At the moment when the ROUTER socket is bound again then a host of messages originating from the DEALER are received. I want all DEALER originating messages to be discarded that were sent to the ROUTER socket while the ROUTER socket was not bound. Is there a way to tweak the settings? Please note, that the ROUTER socket may not close or dispose in a controlled fashion as I want to handle complete application crashes as well.

Thanks a lot for any pointers...

Upvotes: 4

Views: 2479

Answers (1)

Guido Simone
Guido Simone

Reputation: 7952

The process that controls the DEALER socket will need to be enhanced to detect that the connection to the ROUTER is gone. Then you need to close the DEALER socket (with LINGER set to 0 so any queued messages are dropped), create a new socket and connect again. And repeat periodically until a connection is established.

Check out http://zguide.zeromq.org/page:all and read up on the "Paranoid Pirate Pattern". The paranoid pirate worker has the same problem. It is a DEALER socket connecting to a ROUTER and needs to reconnect when the ROUTER goes down.

This solution uses heartbeating to determine when the connection is gone. The guide warns that it can be difficult to get heartbeating right, so keep that in mind as you consider alternatives.

Another approach: note that the 3.2 API includes the new socket monitor API which creates a PAIR socket which can be used to monitor the state of an existing socket. This might allow you to detect that the DEALER's connection to the ROUTER is gone without using heartbeating - but I have not used this API myself. Once you detect the connection is gone, close the socket, reconnect, repeat as above.

Upvotes: 6

Related Questions