How to get the number of messages in a queue using node-amqp

I am using node-amqp as a queue system in a node application. I would like to be able to monitor the status of the queue to find out if we have a sufficient number of desktops, i.e. If the size of the queue increases, we know that we are starting to lag.

I know that from the command line you can use something like:

rabbitmqctl list_queues

Which gives me the exact information I need, but I was wondering if it is even possible to do this from node -amqp?

Thanks in advance.

EDIT

In the end, I just used the rabbitmqctl command-line tool to get the information I needed, this is not a great solution, but here's what I did;

var Logger = require('arsenic-logger');

getQueueMeta(function(info){
    Logger.info(info);
});

/**
* Returns a sparse array with the queue names as the indices
* and the number of messages as the value, e.g.;
*
* info = [ my-queue: 9, my-other-queue: 1 ]
* 
* @param callback
*/
function getQueueMeta(callback){

    var sys = require('sys')
    var exec = require('child_process').exec;

    exec("/usr/local/sbin/rabbitmqctl list_queues", function(error, stdout, stderr) {

        var info = [];

        if (!error){

            var lines = stdout.split(/\n/);

            if (lines.length > 1){

                for (var i=1; i<lines.length-2; i++){
                    var temp = lines[i].split(/\s/);
                    info[temp[0].trim()] = parseInt(temp[1]);
                }

            }

        }

        callback(info);

    });

}
+4
2

, , , - ... node -amqp (0.2.4) , , .

var connection = require("amqp").createConnection();
connection.exchange("exampleExchange", {/*...*/}, function(exchange) {
  connection.queue("exampleQueue", {/*...*/}, function(queue, messageCount, consumerCount){
    console.log("Message count", messageCount);
    console.log("Consumer count", consumerCount);
  });
});
+5

, RabbitMQ AMQP 0.9.1. .

, AMQP , , /. rabbitmqctl AMQP. , rabbitmqctl "", AMQP- "" .

, . connection.queue() .

var q = connection.queue('my-queue', function (queue) {
  console.log('Queue ' + queue.name + ' is open');
});

.NET : queue , . , node.js, , , .

0

All Articles