[rabbitmq-discuss] basic.getall?

Matthew Sackman matthew at lshift.net
Thu Nov 26 10:33:00 GMT 2009


On Thu, Nov 26, 2009 at 10:13:23AM +0000, Matthew Sackman wrote:
> On Thu, Nov 26, 2009 at 09:57:47AM +0000, Robert Raschke wrote:
> > On Wed, Nov 25, 2009 at 9:04 PM, JD Conley <jdc at hive7.com> wrote:
> > > What would be the best approach to get all of the messages in a queue with
> > > as few calls as possible? Right now I'm doing a basic.get loop until the
> > > queue is empty, but I think there is probably a better way.
> 
> Absolutely. Don't use basic.get. Instead subscribe to the queue with
> basic.consume, and if you really want to avoid sending any responses to
> the broker, set the noAck flag to true. That way you don't even have to
> send acks back.

It's just been pointed out to me that of course with this, you won't
know when the queue is empty. You could either periodically, or wait
until the rate drops (which would require measuring rate), call
queue.declare to redeclare the queue which will give you a count of the
msgs in the queue. Depends how quickly you need to know that the queue
has become empty. Something like "if you've not received a msg in the
last 0.5 seconds, try a queue.declare to detect queue-end" may work for
you, but it's more application logic.

Matthew




More information about the rabbitmq-discuss mailing list