As Luca said, no need for DRAFT API here.

zmsg_routing_id() is just a wrapper.



you don't need the call to zframe_new_empty()

before the call to zmsg_pop.

zmsg_pop returns the frame


so


zframe_t *identity = zmsg_pop(msgIn);


as first call after receiving the message just does the trick.


then pop your data from the message while remembering

the identity_frame.


responding you just send a multi-frame message

back to that socket where the identity_frame is the

first one, followed by your data.


________________________________
From: zeromq-dev <[email protected]> on behalf of Luca 
Boccassi <[email protected]>
Sent: Thursday, December 14, 2017 6:28 AM
To: ZeroMQ development list
Subject: Re: [zeromq-dev] CZMQ How to capture identity frame?

On Wed, 2017-12-13 at 20:24 +0000, Stephen Gray wrote:
> Using CZMQ I'm trying to capture the routing identity frame of a
> message received off a ROUTER socket.  I see in the draft API that
> methods exist for this for a SERVER socket;
>
>
>
> #ifdef CZMQ_BUILD_DRAFT_API
>
> //  *** Draft method, for development use, may change without warning
> ***
>
> //  Return message routing ID, if the message came from a ZMQ_SERVER
> socket.
>
> //  Else returns zero.
>
> CZMQ_EXPORT uint32_t
>
>     zmsg_routing_id (zmsg_t *self);
>
>
>
> //  *** Draft method, for development use, may change without warning
> ***
>
> //  Set routing ID on message. This is used if/when the message is
> sent to a
>
> //  ZMQ_SERVER socket.
>
> CZMQ_EXPORT void
>
>     zmsg_set_routing_id (zmsg_t *self, uint32_t routing_id);
>
>
> I believe my installation of CZMQ built the draft API; but I cannot
> work out how to access it in my code, is a pre-processor definition
> required?  Also do the these methods also work for ROUTER sockets?
>
> Really though, I'd rather stick with the stable version. Please could
> someone enlighten me on how to get the identity frame using CZMQ?  I
> tried this:
>
> //Inbound from ROUTER so will be carrying an identity frame
> zframe_t *identity = zframe_new_empty();
> identity = zmsg_pop(msgIn);//strip off id frame
>
> but it crashes at runtime.
>
> With thanks,
>
> Stephen

You don't need any special API. From the zmq_socket manpage:

"When receiving messages a ZMQ_ROUTER socket shall prepend a message
part containing the routing id of the originating peer to the message
before passing it to the application."

--
Kind regards,
Luca Boccassi
_______________________________________________
zeromq-dev mailing list
[email protected]
https://lists.zeromq.org/mailman/listinfo/zeromq-dev

Reply via email to