brettviren/cppzmq-tour

cppzmq v4.7.1 zmq::message_t::routing_id method

Opened this issue · 3 comments

Hi.

Thank you for the guide. It is great and keep up the good work!

Just wondering if some of these instructions/examples are no longer correct or applicable.

SERVER Routing ID
When we receive and send messages via a socket of type SERVER our application must manage a "routing ID" in order to associate the messages with a remote CLIENT socket. We do this by getting and setting this ID from/on the message as:

// After we receive a message, remember its routing ID:
uint32_t rid = msg.routing_id();

// Later, just before sending, we make sure to set the ID:
zmq::message_t msg2;
msg2.set_routing_id(rid);

I have downloaded the cppzmq 4.7.1 and tried to do the following:

uint32_t rid = msg.routing_id();

but met with the error error: ‘class zmq::message_t’ has no member named ‘routing_id’ which I think it probably due to cppzmq being deprecated?

So questions are:

  1. Is there another way to do this? Or is this no longer needed (hence deprecated)?

  2. In your example CLIENT/SERVER, is this the same as the other people's example where they talk about a simple REQ/REP server? E.g. zmq.REQ and zmq.REP in https://learning-0mq-with-pyzmq.readthedocs.io/en/latest/pyzmq/patterns/client_server.html

  3. The reason for question (2) is that, if they are the same, will the routing_id be required because they seem not needed in the REQ/REP example.

Thank you very much!

Actually, I think I have answered my own general question about the routing_id is not found. It is because I am using libzmq 4.3.5 stable build which does not yet have that feature. I can enable the C++ wrapper in cppzmq but it will not link. So I guess this is question (1) answered.

Nonetheless, I am still new to this library and unsure of questions (2) and (3). If you could easily fill me in, that'll be great!

Anyway, have a good day and thank you for your work. :-)

  1. routing_id() is still defined:

https://github.com/zeromq/cppzmq/blob/master/zmq.hpp#L630

I don't see any deprecation. Actually, just the opposite, CLIENT and SERVER are both relatively new socket types (though still a few years old).

I wonder if you are compiling w/out "draft" sockets supported. You'll need to compile with "draft" to use SERVER at all.

  1. No, CLIENT and SERVER are distinct socket types from REQ or REP and likewise from DEALER and ROUTER.

  2. routing_id is specific to SERVER. ROUTER has a very similar concept but the ID is placed in-band in the message and explicitly by application code.

BTW, if you want to study some example code that deals with this SERVER and ROUTER near-symmetry you can look at, eg:

https://github.com/brettviren/zio/blob/master/src/util.cpp#L58

and the similar send_serverish() in that file.

Our posts crossed.

The latest libzmq is 4.3.4 and it has CLIENT and SERVER but it also needs to be compiled with "draft" support turned on.