ZMQ_MSG_ROUTING_ID(3)

πŸ’– ZMQ_MSG_ROUTING_ID πŸ’–

okay bestie, so this one's from the 0MQ Manual and it's literally so cute and short, we're gonna eat it up. it's a 3 page, meaning it's about a library function, and the function is zmq_msg_routing_id. yes queen, we're doing message routing IDs today. grab a boba. πŸ§‹


✨ NAME ✨

zmq_msg_routing_id β€” return routing ID for message, if any

like... that's it. that's the whole job. it gives you the routing ID of a message if there is one, and if there isn't, no drama, it just says zero. πŸ’…


✨ SYNOPSIS ✨

uint32_t zmq_msg_routing_id (zmq_msg_t *message);

one function, one pointer, one uint32_t coming back at ya. so clean. so iconic. πŸ‘‘


✨ DESCRIPTION ✨

so the way that zmq_msg_routing_id() works is: it returns the routing ID for the message, if any. that "if any" is doing a LOT of heavy lifting there, bestie, so let's talk about when you actually get one. πŸ¦‹

the routing ID is set on all messages received from a ZMQ_SERVER socket. every single one. no cap.

and then β€” and this is the part where it gets useful β€” to send a message to a ZMQ_SERVER socket, you must set the routing ID of a connected ZMQ_CLIENT peer. so like, you can't just fire a message into the void and hope. you need the ID. it's giving "you need the guest list to get into the party." πŸŽ€

πŸ’€ oh and also: routing IDs are transient. meaning they are NOT forever. do not fall in love with a routing ID. do not store it in a little jar. it's a moment, not a marriage. remember that fr fr.

✨ RETURN VALUE ✨

  • if there is no routing ID, it returns zero. simple. nothing. bye. πŸ™ˆ
  • otherwise it returns an unsigned 32-bit integer greater than zero. so like, 1 and up. positive vibes only. ✨

so like, quick vibe check: 0 = no ID, >0 = yes ID. that's the whole test, bestie. 🫢


✨ EXAMPLE ✨

receiving a client message and routing ID. look at this lil guy go:

void *ctx = zmq_ctx_new ();
assert (ctx);

void *server = zmq_socket (ctx, ZMQ_SERVER);
assert (server);
int rc = zmq_bind (server, "tcp://127.0.0.1:8080");
assert (rc == 0);

zmq_msg_t message;
rc = zmq_msg_init (&message);
assert (rc == 0);

//  Receive a message from socket
rc = zmq_msg_recv (server, &message, 0);
assert (rc != -1);
uint32_t routing_id = zmq_msg_routing_id (&message);
assert (routing_id);

okay so what's happening here: make a context, make a ZMQ_SERVER socket, bind it to "tcp://127.0.0.1:8080", init a message, receive into it, then pull the routing ID out with zmq_msg_routing_id. and the final assert (routing_id) is literally the plot twist β€” it passes because a message that came in from a ZMQ_SERVER socket has a routing ID. 🌈


✨ SEE ALSO ✨


✨ AUTHORS ✨

this page was written by the 0MQ community. 🫢 if you wanna make a change, please read the 0MQ Contribution Policy at http://www.zeromq.org/docs:contributing. the community said come thru and contribute, and honestly? slay.


okay that's the whole page, no notes. 🌸 stay transient, stay iconic. this was the zmq_msg_routing_id page, 0MQ version 4.3.5, dated 10/09/2023 β€” mwah, love u, bye bestie! πŸ’–πŸŽ€βœ¨

πŸ“¦ where this page comes from