[zeromq-dev] [Fwd: Re: socket call back when using the zmq_loop]

Martin Sustrik sustrik at 250bpm.com
Fri Dec 18 18:26:23 CET 2009


Hi Sebastien,

>> The only case where you need multiple 0MQ sockets is when using multiple
>> messaging patters simultaneously from the same thread, say both
>> request/reply and publish/subscribe.
> 
> That exactly what I planed to do. Use the filtering layer of the
> zmq_socket and link that filtering to a specific callback. But maybe
> It's not the better way to do that!

If all you need is filtering why not do it in a straightforward way?

zmq::socket_t s (ctx, ZMQ_SUB);
s.connect ("tcp://server001:5555");
s.setsockopt (ZMQ_SUBSCRIBE, "abc.*", 5);
while (true) {
     zmq::message_t msg;
     s.recv (&msg);
     process_message (msg);
}

Obviously, if you need a callback, just use function pointer instead of 
hard-wired 'process_message' function in the above example.

> So If I understand correctly the filtering should be done by the
> application or use one thread per zmq socket and let the socket do the
> filtering or use the low level zmq_poll and make my own loop.

Nope. 0MQ should do the filtering. The question is why would you want to 
use multiple sockets. If you want to receive messages from two sources, 
just connect/bind the same socket twice:

zmq::socket_t s (ctx, ZMQ_SUB);
s.connect ("tcp://server001:5555");
s.connect ("tcp://server002:5555");
s.setsockopt (ZMQ_SUBSCRIBE, "abc.*", 5);
  etc.

Martin



More information about the zeromq-dev mailing list