[rabbitmq-discuss] py-amqplib basic_consume

Matthias Radestock matthias at lshift.net
Fri Nov 21 22:53:37 GMT 2008


Tsuraan,

tsuraan wrote:
> Ok, so now I'm trying to get basic_consume to work, and it's behaving
> very strangely.  As before, I first run a producer that puts 1000
> messages into a queue called toshred.  Once that has run, I run my new
> consumer code, which just prints that it got something to consume.  It
> doesn't acknowledge the message, it doesn't do anything the slightest
> bit useful.  However, it does appear to devour messages like mad.
> Every time I run this "consumer", it calls the consume method once,
> but over 200 messages will be gone from the toshred queue (as
> determined by a passive declaration of that queue).

The passive declaration of a queue tells you the number of messages 
present in the queue (and committed if the channel on which they were 
published is transacted) *that are not awaiting acknowledgement*.

When a client has subscribed to a queue with basic.consume, the queue 
will send it messages as fast as it can, until network back pressure 
kicks in.

So it is perfectly normal for there to be a discrepancy between the 
number of messages published vs the number of messages received + the 
message count returned by queue.declare-ok - the difference is accounted 
for by messages "in flight".

> Two questions: why are messages being removed from the queue?

They are not actually being removed until an ack is received, but they 
are unavailable for consumption by another consumer.

> It doesn't seem like any messages are being acknowledged, so I wouldn't
> expect any messages to be dequeued.

Actually, in your example you are using ...

>   chan.basic_consume('toshred', no_ack=True, callback=consume)

with the no_ack flag set to True. That causes messages to be 
automatically "self-acknowledged" by the server. In other words, as soon 
as the queue has sent them on their way they are removed from the queue 
and gone for good.


Matthias.




More information about the rabbitmq-discuss mailing list