Number of items (length) of a queue

52 views
Skip to first unread message

m94asr

unread,
Oct 13, 2008, 9:23:26 AM10/13/08
to AMQP
Is there away to find out how many elements are still in a queue?

MQ.queue('test1').size --> integer

Thanks,
-A

Ben Hood

unread,
Oct 13, 2008, 10:14:04 AM10/13/08
to ruby...@googlegroups.com
Armin,

On Mon, Oct 13, 2008 at 2:23 PM, m94asr <m94...@gmail.com> wrote:

> Is there away to find out how many elements are still in a queue?

From a protocol perspective (I'm not too sure how the Ruby library
exposes this), the Queue.DeclareOk response to the Queue.Declare
command returns the queue depth (i.e. the number of messages committed
on ingress). This does not include messages on ingress pending a TX
commit or messages on egress pending acks from consumers. Since this
is an idempotent command, it is currently your best bet from a pure
Ruby perspective.

HTH,

Ben

Aman Gupta

unread,
Oct 13, 2008, 1:42:54 PM10/13/08
to ruby...@googlegroups.com
With master, you can use:

MQ.queue('crawls').status do |messages, consumers|
puts "#{messages} messages and #{consumers} consumers"
end

Aman

Ben Hood

unread,
Oct 13, 2008, 2:28:41 PM10/13/08
to ruby...@googlegroups.com
Hey Aman,

On Mon, Oct 13, 2008 at 6:42 PM, Aman Gupta <themast...@gmail.com> wrote:
> MQ.queue('crawls').status do |messages, consumers|
> puts "#{messages} messages and #{consumers} consumers"
> end

That's what I call syntactic sugar!

+1 to your lib for this :-)

Ben

Reply all
Reply to author
Forward
0 new messages