[zeromq-dev] disabling receiving messages from queue
Martin Sustrik
sustrik at fastmq.com
Tue Aug 4 15:57:21 CEST 2009
Hi Pavel,
> Can I disable receiving messages from spcecified queue by
> api_thread_t::receive()?
> Real use case: my application has one api_thread_t, it receives
> requests, process it and sends responses. While processing request, it
> sends/receives messages to another applications. I want to implement
> limit for number of currently processing messages. Easiest
> implementation for me looks like this: when number of currently
> processing request goes above limit, i block receiving messages from
> requests queue. In this case only messages that used in processing will
> be received, no new request messages.
>
> Now i'm thinking about:
> 1) more complex realization with two api_thread_t, non-blocking
> receive() and sleep() functions.
> 2) more complex realization with blocking receive() but with two
> application threads with syncronization between them.
>
> May be threre is more elegant solution for my situation?
No, there isn't :(
What you speak about actually boils down to the need for polling on
arbitrary subset of queues.
Rather than implementing 1. or 2. you may consider submitting a patch to
0MQ that would allow for receiving only from a subset of queues. Say:
api->receive (&msg, false, 1 << queue_id1 | 1 << queue_id2);
Have a look at the implementation of zmq::api_thread_t::receive
function. It's actually a pretty dumb loop that round robins through the
list of queues and fetches a message from one of them.
Making it ignore subset of queues seems to be a pretty trivial change.
Thoughts?
Martin
More information about the zeromq-dev
mailing list