Identities and Addresses
The identity concept in ØMQ refers specifically to ROUTER sockets and how they identify the connections they have to other sockets. More broadly, identities are used as addresses in the reply envelope. In most cases, the identity is arbitrary and local to the ROUTER socket: it’s a lookup key in a hash table. Independently, a peer can have an address that is physical (a network endpoint like “tcp://192.168.55.117:5670”) or logical (a UUID or email address or other unique key).
An application that uses a ROUTER socket to talk to specific peers can convert a logical address to an identity if it has built the necessary hash table. Because ROUTER sockets only announce the identity of a connection (to a specific peer) when that peer sends a message, you can only really reply to a message, not spontaneously talk to a peer.
This is true even if you flip the rules and make the ROUTER connect to the peer rather than wait for the peer to connect to the ROUTER.
However, you can force the ROUTER socket to use a logical address
in place of its identity. The zmq_setsockopt() reference page calls this
setting the socket identity. It works as
follows:
The peer application sets the
ZMQ_IDENTITYoption of its peer socket (DEALER or REQ) before binding or connecting.Usually the peer then connects to the already bound ROUTER socket, but the ROUTER can also connect to the peer.
At connection time, the peer socket tells the router socket, “Please use this identity for this connection.” ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access