<html><head></head><body bgcolor="#FFFFFF"><div>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</div>
<div><pre class="lang-java prettyprint" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.8em; margin-left: 0px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font: inherit; vertical-align: baseline; word-wrap: break-word; background-color: rgb(240, 240, 240); ">
<code style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font: inherit; vertical-align: baseline; background-color: rgb(240, 240, 240); white-space: normal;"><span class="pln" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font: inherit; vertical-align: baseline; ">list</span><span class="pun" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font: inherit; vertical-align: baseline; ">.</span><span class="pln" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font: inherit; vertical-align: baseline; ">add</span><span class="pun" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font: inherit; vertical-align: baseline; ">(</span><span class="pln" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font: inherit; vertical-align: baseline; ">blockingQueue</span><span class="pun" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font: inherit; vertical-align: baseline; ">.</span><span class="pln" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font: inherit; vertical-align: baseline; ">take</span><span class="pun" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font: inherit; vertical-align: baseline; ">());</span><span class="pln" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font: inherit; vertical-align: baseline; "><br>
blockingQueue</span><span class="pun" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font: inherit; vertical-align: baseline; ">.</span><span class="pln" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font: inherit; vertical-align: baseline; ">drainTo</span><span class="pun" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font: inherit; vertical-align: baseline; ">(</span><span class="pln" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font: inherit; vertical-align: baseline; ">list</span><span class="pun" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font: inherit; vertical-align: baseline; ">);</span></code></pre>
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.�</div>
<div><br></div><div>-Cameron Davison</div><div><br>On Nov 10, 2011, at 3:08 AM, Matthias Radestock &lt;<a href="mailto:matthias@rabbitmq.com">matthias@rabbitmq.com</a>&gt; wrote:<br><br></div><div></div><blockquote type="cite">
<div><span>On 10/11/11 08:51, pavuuu wrote:</span><br><blockquote type="cite"><blockquote type="cite"><span>When using &#39;BasicConsume&#39; without setting BasicQos on channel, it seems it</span><br></blockquote></blockquote>
<blockquote type="cite"><blockquote type="cite"><span>is connecting to RabbitMQ everytime I call &#39;consumer.Queue.Dequeue()&#39;.</span><br></blockquote></blockquote><span></span><br><span>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.</span><br>
<span></span><br><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><span>Btw, you do realise that the Dequeue() operation is client-side only,</span><br></blockquote></blockquote>
</blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><span>right? i.e. it is simply manipulating a client side buffer which is</span><br></blockquote></blockquote>
</blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><span>filled as and when the client receives a message from the server.</span><br></blockquote></blockquote>
</blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span></span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span>yes, I understood that. When I set the prefetch to 1000, at client side a</span><br>
</blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span>buffer is being maintained which will contain a maximum of 1000 messages.</span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">
<span>When I call dequeue, it is giving me the message from this buffer.</span><br></blockquote></blockquote><span></span><br><span>The buffer is there regardless of Basic.Qos. But without Basic.Qos it can grow unbounded if the client app isn&#39;t draining it fast enough. With Basic.Qos the size is bounded to the prefetch size.</span><br>
<span></span><br><blockquote type="cite"><blockquote type="cite"><span>And if there are less than 1000 messages in buffer, it refills the buffer</span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">
<span>if there are any messages in the queue bound to it.</span><br></blockquote></blockquote><span></span><br><span>The refilling is triggered by the client ack&#39;ing messages.</span><br><span></span><br><span></span><br>
<span>Matthias.</span><br><span>_______________________________________________</span><br><span>rabbitmq-discuss mailing list</span><br><span><a href="mailto:rabbitmq-discuss@lists.rabbitmq.com">rabbitmq-discuss@lists.rabbitmq.com</a></span><br>
<span><a href="https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss">https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss</a></span><br></div></blockquote></body></html>