Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AMQP - How many consumers on a queue?

Using AMQP module for Node JS and RabbitMQ, is there any way to tell how many subscribers there are on a queue?

We have multiple queues on the default exchange for multiple regions. When one region is down, instead of routing messages to that queue, we'll instead route to the next-best AMQP queue (region) that is actively listening.

Is there any way to count the number of subscribers on a queue?

We have a heartbeat set up so the server should be able to track accurately.

Thanks!

like image 378
Chris Nolet Avatar asked Oct 21 '22 10:10

Chris Nolet


1 Answers

I ended up figuring out this piece of gold:

var conn = amqp.createConnection({ url: process.env.AMQP, heartbeat: 60 });

conn.queue('queue-name').on('queueDeclareOk', function(args) {
  console.log('Total Consumers: ' + args.consumerCount);
}

Works perfectly :)

like image 72
Chris Nolet Avatar answered Oct 24 '22 04:10

Chris Nolet