[rabbitmq-discuss] Is there a way to receive multiple message using a single synchronous call ?

Vikram Viswanathan vikram.vis at gmail.com
Mon Jun 10 17:06:44 BST 2013


Thanks.

I have another question. If I use basic.consume, register a callback, 
then is there a way where I can can cancel the consumer after N message 
is received ?

I tried calling Channel.basicCancel(consumerTag) in the callback, but 
this cancels the consumer only after all messages in the queue is 
received. I understand that its difficult to cancel the consumer on its 
own callback, but if cancel the consumer in another thread then I afraid 
I will run into a bunch race conditions and I will not be able to get 
exactly the number of messages I want.

I am looking into this because I am implementing http long polling in 
server and the http requests are translated into ampq call to rabbitmq 
server. I do not want to make basic.get() with a timeout because this 
will cause my thread to block for the duration and cause scalability issue.

-Vikram


On 06/10/2013 03:05 AM, Simon MacMullen wrote:
> On 09/06/13 02:23, Vikram Viswanathan wrote:
>> When I know that there are N messages( N could be a small value less
>> than 10) in the queue, then I should be able to do something like
>> channel.basic_get(String queue, boolean autoAck , int numberofMsg ). I
>> don't want to make multiple requests to the server and  I don't want to
>> register a handler to receive messages.
>>
>> Is there a way ?
>
> I'm afraid not, you can either receive one message with basic.get or 
> multiple with basic.consume.
>
> Cheers, Simon
>
>



More information about the rabbitmq-discuss mailing list