Open reza-ebrahimi opened 7 years ago
Isn't the identity used for that purpose?
@bluca Yes, of course! but identity doesn't enough in dealing with some situations, for example, one problem happened when a DEALER socket lost (disconnected) its connection, so that socket identity still be in ROUTER socket side and exists their identity state in application code, if you send any data to disconnected DEALER socket it will face with access violation error. so in cause of the error, application code doesn't know about disconnected socket state or doesn't notified about that to consider another tasks such as removing socket identity handle.
I think this is a ZeroMQ kernel task to provide a identity manager in ROUTER socket side and do proper tasks (adding, removing, querying), by now there is no notifying mechanism from ROUTER socket about disconnection of ROUTER clients (ex. DEALER sockets).
Isn't ROUTER_MANDATORY https://github.com/zeromq/libzmq/blob/master/doc/zmq_setsockopt.txt#L705 a solution for that already? It will return an error in such cases
The socket monitor will send a disconnect event and the application can remove the DEALER. Isn't that all you need?
Edit: sorry, the EVENT_DISCONNECTED only includes the endpoint, which works for a single connection but not for a ROUTER sockets with 10 DEALERS. See #2306. So I should have asked: Would #2306 solve your problem?
Yes, That is! I need to know which peer is disconnected, to do this zeromq might provide me at least peer's identity and another useful information such as socket lost reason:
Disconnection event structure (suggestion):
PRs are most welcome :)
If we want to modify zmq monitoring system, we should useZMQ_PAIR
socket,
documentation says:
A socket of type ZMQ_PAIR can only be connected to a single peer at any one time. No message routing or filtering is performed on messages sent over a ZMQ_PAIR socket.
in this case we should create and connect multiple instance of ZMQ_PAIR
socket based on how many peers connected to ROUTER
socket, the problem here is monitor socket only works in inproc
protocol scheme, so we cannot connect ZMQ_PAIR
socket to a DEALER
socket from ROUTER
side.
Also using a ZMQ_PAIR
socket with ROUTER
doesn't give us its peers events, this only works with ROUTER
socket itself.
Guys, This is requirement that we were looking for in our application as well. Has this been addressed in any form ? Please guide.
It has not - pull requests are welcome
Hi We also wanted a solution like this. Is it available now?
A disconnection is notified using [identity, b''] (ie one-message-with-identity-and-empty-string) in pyzmq so you actually know who and when it disconnected. I would assume it's similar in the lower level api.
@dbivolaru ,
That only happens if you set appropriate flags for ZMQ_ROUTER_NOTIFY
socketopt.
From libzmq/master docs, it seems that this option is still in draft state and not part of the general release.
Did you build libzmq with --enable-drafts
option?
If not, is this socketopt out of it's draft state?
Thanks!
Any updates or approachs on this? My server with router keep crashing when I try to send msg to disconnected dealer(due to bad internet). NEED HELP !
Any updates or approachs on this? My server with router keep crashing when I try to send msg to disconnected dealer(due to bad internet). NEED HELP !
NVM setting zmq_router_manadatory to 0 did the trick which is default.
zmq::socket_t cms_router(*ctx, zmq::socket_type::router);
cms_router.set(zmq::sockopt::router_mandatory,0); //<--- ignore error when dealer doesnt exist
cms_router.bind("tcp://*:" + port);
There are 10 Clients (DEALER sockets) that are connected to a ROUTER socket, if all clients send message to ROUTER socket and in ROUTER side for sending reply response to exactly such a DEALER it might know about its handle, to do this there is no API to manage DEALER handles in ROUTER side, so manager should do some tasks like adding, removing or query a handle.