Check RabbitMQ queue size from client

后端 未结 9 1253
终归单人心
终归单人心 2021-01-30 20:12

Does anyone know if there\'s a way to check the number of messages in a RabbitMQ queue from a client application?

I\'m using the .NET client library.

9条回答
  •  灰色年华
    2021-01-30 21:07

    If you want to do this in .NET, check which version of the client library you are using.

    I'm using the 2.2.0 version and I had to use BasicGet(queue, noAck).
    In this version of the library, QueueDeclare() only returns a string containing the queue name.

    BasicGetResult result = channel.BasicGet("QueueName", false);
    uint count = result != null ? result.MessageCount : 0;
    

    I know from the 2.6.1 version, QueueDeclare() returns an object of type QueueDeclareOk.

    QueueDeclareOk result = channel.QueueDeclare();
    uint count = result.MessageCount;
    

    Alternatively, you can call from the command line:

    \sbin\rabbitmqctl.bat list_queues
    

    And you see the following output:

    Listing queues...
    QueueName 1
    ...done.

提交回复
热议问题