[rabbitmq-discuss] Tracking Queues and Exchanges

Chuck Remes cremes.devlist at mac.com
Wed Jan 21 15:00:42 GMT 2009


On Jan 21, 2009, at 2:37 AM, Ben Hood wrote:

> Daniel,
>
> On Wed, Jan 21, 2009 at 4:03 AM, Daniel N <has.sox at gmail.com> wrote:
>> I've tried to locate this in the docs but I haven't been able to  
>> find it
>> (not that it's not there).
>
> Have you read this?
>
> http://www.rabbitmq.com/admin-guide.html#server_status
>
>> Specifically, what queues are on any given exchange, how many  
>> messages it's
>> doing per s etc.
>
> This is not possible because we don't expose statistics for delivered
> messages, i.e. the case when messages don't get queued, just
> delivered.
>
>> For Queues, how many messages are in it at any given time, how  
>> many / what
>> clients are reading from it?
>
> You should be able to get these. See the above documentation.
>
>> I'm currently using the amqp ruby library to connect and setup my  
>> workers.
>
> These is not exposed by the amqp ruby library, just via the  
> rabbitmqctl CLI.

You can retrieve the number of messages in the queue via the ruby amqp  
library using the #status method.

The following code isn't great but it does illustrate the point. :)

The rest of Ben's reply is correct.

cr


require 'rubygems'
require 'mq'

AMQP.start do
   def setup_exchange
     exchange = MQ.direct('bar')
     EM.add_periodic_timer(1) do
       exchange.publish "random number #{rand(1000)}"
     end
   end

   def synchronous_subscribe
     @foo = MQ.queue('foo queue')
     @foo.bind 'bar'
     EM.add_periodic_timer(2) do
       @foo.pop do |body|
         p body
       end
     end
   end

   def get_status
     EM.add_periodic_timer(1) do
       @foo.status do |message_count|
         p message_count
       end
     end
   end

   setup_exchange
   synchronous_subscribe
   get_status
end




More information about the rabbitmq-discuss mailing list