[zeromq-dev] Devices, and pipeline again

Matt Weinstein matt_weinstein at yahoo.com
Thu Jul 29 19:15:53 CEST 2010


On Jul 29, 2010, at 11:46 AM, Pieter Hintjens wrote:

> Hi All,
>
> I'm writing a new generic zmq_device that will replace zmq_queue,
> zmq_forwarder and zmq_streamer.
>
> The code is here: http://dpaste.de/4DcP/
>
> The zmq_device works a lot like the zmq::device method.  There is
> documentation at the start of the source code, which I'll expand to
> become a man page when this is stable.
>
> Anyone who is already using devices: your feedback would be useful.
> Especially, do you use multiple in/out sockets (I've renamed that to
> 'frontend' and 'backend' here)?  And do you connect outwards from your
> device, using it as a proxy, or do you connect into it, using it as a
> mini-broker?
>
> Second thing, those pipeline sockets again.  Here is the core of the
> generic device, acting as broker (such short sweet code, thank you
> 0MQ!):
>
>        int device = parse_device (argv [1]);
>        switch (device) {
>            case ZMQ_QUEUE:
>                frontend_type = ZMQ_XREP;   //  Client
>                backend_type  = ZMQ_XREQ;   //  Service
>                break;
>            case ZMQ_FORWARDER:
>                frontend_type = ZMQ_SUB;    //  Subscriber
>                backend_type  = ZMQ_PUB;    //  Publisher
>                break;
>            case ZMQ_STREAMER:
>                frontend_type = ZMQ_PULL;   //  Puller
>                backend_type  = ZMQ_PUSH;   //  Pusher

+1
The actor is obvious (the user's thread) so this makes sense.
(Definitely better than ZMQ_NOW and ZMQ_LATER :-) )

>                break;
>            default:
>                return (1);             //  Invalid device
>        }
>        //  Create sockets, configure them, and start the device
>        zmq::context_t context (1);
>        zmq::socket_t frontend (context, frontend_type);
>        zmq::socket_t backend (context, backend_type);
>        if (frontend_type == ZMQ_SUB)
>            frontend.setsockopt (ZMQ_SUBSCRIBE, "", 0);
>        frontend.bind (argv [2]);
>        backend.bind (argv [3]);
>        zmq::device (device, frontend, backend);
>
> As you can see I'm using ZMQ_PUSH and ZMQ_PULL in place of
> ZMQ_DOWNSTREAM and ZMQ_UPSTREAM.  It seems to work.  A node pulls
> data, works on it, and pushes it on.  So nodes are pullers, or
> pushers, or both.  It's short, verbish (like the other socket types)
> and feels clear.
>
> If there are no outright objections after a day or so I'll start to
> deprecate ZMQ_DOWNSTREAM/UPSTREAM and replace with ZMQ_PUSH/PULL.
> We'll keep the old definitions around, of course, this does not break
> the ABI.
>
> -Pieter
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev




More information about the zeromq-dev mailing list