[zeromq-dev] Questions about ROUTER socket and identity.

Kal Sze swordangel at gmail.com
Mon Jan 9 07:13:45 CET 2017


According to http://api.zeromq.org/4-0:zmq-setsockopt#toc8:

    "If two clients use the same identity when connecting to a ROUTER,
the ROUTER socket shall accept only the first such client and reject
the others".

However, http://zguide.zeromq.org/php:chapter3#The-Extended-Reply-Envelope
also says these:

    "ZeroMQ v3.0 and later generate a 5 byte identity by default (0 +
a random 32bit integer)."
    "The ROUTER socket invents a random identity for each connection
with which it works. If there are three REQ sockets connected to a
ROUTER socket, it will invent three random identities, one for each
REQ socket."

So I have three questions:

1. The ROUTER socket invent 5-byte random identities for *both* REQ
and DEALER sockets, correct?
2. Does all of these mean that, in practice, I don't need to set the
ZMQ_IDENTITY option on my REQ or DEALER sockets that connect to a
ROUTER socket, as long as I don't have a very large number of REQ or
DEALER clients (2^32)?
3. Does the ROUTER socket ensure that it does not route replies to the
wrong REQ or DEALER socket? E.g., given the following sequence of
    a) a DEALER socket connects to the ROUTER socket;
    b) the ROUTER socket assigns a random identity of 3721 to the REQ socket;
    c) the ROUTER socket receives a message from DEALER 3721 and
returns it to the application for processing;
    d) the DEALER 3721 drops out (!!!);
    e) another DEALER connects to the DEALER;
    f) the application is done processing the message and wants to
send a reply to the original DEALER 3721.

Is it at all possible that, at step e), the ROUTER assigns identity
3721 to the new DEALER by mistake, and so ends up sending the reply to
the wrong DEALER socket? Or is the ROUTER smart enough to not make the
identity 3721 available to other connecting sockets until it tries to
send a reply and only then realize that the original DEALER 3721 had
dropped out?


More information about the zeromq-dev mailing list