[rabbitmq-discuss] basic.Get and basic.Consume on the same queue

Marek Majkowski majek04 at gmail.com
Wed Mar 7 14:03:48 GMT 2012

On Wed, Mar 7, 2012 at 13:52, Greg <gregory.sainson at gmail.com> wrote:
> Hi,
> I can't find any info on the web about it.
> I currently have different programs that consumes the same queue.
> One program is registered to the queue with a basic.Consume.
> The other one is receiving messages with basic.Get. Unfortunately, It
> doesn't get any messages, basic.Get always returns null, like the queue is
> empty.
> If I change it with a basic.Consume, it works fine. I'm using the Java
> client of RabbitMQ.
> Anyone has any idea with this happens?

If you're using Basic.Consume without setting Basic.QOS, Rabbit
sends a bulk of messages to the consumer. (in hundreds of messages).

Assuming the consumer uses Acks, the messages are then slowly
marked as Acknowledged and deleted.

But in the meantime all the messages were already sent to the
BasicConsume client - thus Basic.Get will find that there
aren't any messages ready!

The solution is to configure prefetch count using Basic.Qos
and also you must use Acknowledgments. (Basic.Qos without
acks makes no sense).

When you change second consumer to use BasicConsume,
it will hang and wait for mesages. Rabbit than sees:
okay, there are two consumes waiting on that queue.
When a new message arrives Rabbit will make a decision
where to send the message. It will try to do something
like round-robin. Thus - your second consumer will
receive some messages (every second one in a perfect

Hope that helps,

More information about the rabbitmq-discuss mailing list