[rabbitmq-discuss] asynchronous fetching messages from rabbitMQ queues

Cameron Davison cameron.davison at gmail.com
Thu Nov 10 15:09:08 GMT 2011


If you are using the java-client the QueueingConsumer accepts messages from
the rabbitmq and buffers them into a BlockingQueue so that when you call
nextDelivery you just grab the next one off the queue. You could implement
your own Consumer that does the same thing and use something like

list.add(blockingQueue.take());
blockingQueue.drainTo(list);

to drain all the elements in the array blocking queue into a passed in set.
Only thing that you have to worry about then would be dealing with
cancel,cancel-ok,shutdown signals without adding them into your passed in
set.

-Cameron Davison

On Nov 10, 2011, at 3:08 AM, Matthias Radestock <matthias at rabbitmq.com>
wrote:

On 10/11/11 08:51, pavuuu wrote:

When using 'BasicConsume' without setting BasicQos on channel, it seems it

is connecting to RabbitMQ everytime I call 'consumer.Queue.Dequeue()'.


Dequeue *never* triggers an interaction with the server. Messages are sent
by the server to the client (and buffered in the consumer.Queue) in the
background. Basic.Qos controls the flow of these messages. Without a
prefetch limit, the server sends messages to the client as soon as they
become available in the queue. With a prefetch limit of N, the server will
send at most N message and then send no more until it receives one or more
acks.

Btw, you do realise that the Dequeue() operation is client-side only,

right? i.e. it is simply manipulating a client side buffer which is

filled as and when the client receives a message from the server.


yes, I understood that. When I set the prefetch to 1000, at client side a

buffer is being maintained which will contain a maximum of 1000 messages.

When I call dequeue, it is giving me the message from this buffer.


The buffer is there regardless of Basic.Qos. But without Basic.Qos it can
grow unbounded if the client app isn't draining it fast enough. With
Basic.Qos the size is bounded to the prefetch size.

And if there are less than 1000 messages in buffer, it refills the buffer

if there are any messages in the queue bound to it.


The refilling is triggered by the client ack'ing messages.


Matthias.
_______________________________________________
rabbitmq-discuss mailing list
rabbitmq-discuss at lists.rabbitmq.com
https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/attachments/20111110/36a8079a/attachment.htm>


More information about the rabbitmq-discuss mailing list