Reputation: 2824
... or how does zmq deal with clients that disconnect? Is there some sort of timeout for a queue where it can continue receiving messages if the client disconnects, but clean up after itself after so many seconds?
Upvotes: 2
Views: 666
Reputation: 6669
There are several different strategies you can use, and it depends on your needs (no one answer fits all).
In general, if the client disconnects, its queue on the server side will be deleted. This is true of PUB to SUB flows, and PUSH to PULL flows.
If you want to handle frequent disconnections you can use ROUTER-DEALER and set an identity on the connection (at the DEALER side, before connecting). Then the ROUTER will queue messages for the DEALER even if it goes away and comes back. You can then limit the size of that queue using the HWM.
If you want timeouts, it's a little more tricky since ZeroMQ either keeps messages forever, or drops them immediately if they can't be queued. You need to queue messages in your own list structures in the server, set the HWM to 1, and use non-blocking sends to push them off your queue as there's space for them. Then you can expire clients yourself and delete the queues associated with them. It sounds like work but is pretty simple.
Upvotes: 1
Reputation: 66739
See: http://api.zeromq.org/2-1:zmq-setsockopt
ZMQ sockets have a concept of high water mark.
From the docs:
The high water mark is a hard limit on the maximum number of outstanding messages ØMQ shall
queue in memory for any single peer that the specified socket is communicating with.
If this limit has been reached the socket shall enter an exceptional state and depending on
the socket type, ØMQ shall take appropriate action such as blocking or dropping sent messages.
For each type of zmq sockets (REQ, REP, PUB, SUB etc) you can check the document on it's behavior - if it blocks sending of messages or drops them.
Mostly when the client disconnects, it drops the messages. If that is important to you, you must build message persistence and reliability on top of ZMQ patterns.
Upvotes: 2