Check RabbitMQ queue size from client

2019-03-08 10:11发布

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.

8条回答
虎瘦雄心在
2楼-- · 2019-03-08 10:46

You can use the IModel's MessageCount method, documented here

http://www.rabbitmq.com/releases/rabbitmq-dotnet-client/v3.6.4/rabbitmq-dotnet-client-3.6.4-client-htmldoc/html/type-RabbitMQ.Client.IModel.html#method-M:RabbitMQ.Client.IModel.MessageCount(System.String)

edit: I know this is a very old post, but it is the first google response, and I hope it will help people looking for this answer in the future.

查看更多
别忘想泡老子
3楼-- · 2019-03-08 10:47

At least as of RabbitMQ 3.3.5, you can do this in a C# program without any RabbitMQ client library by calling the RabbitMQ Management HTTP API:

// The last segment of the URL is the RabbitMQ "virtual host name". 
// The default virtual host name is "/", represented urlEncoded by "%2F".
string queuesUrl = "http://MY_RABBITMQ_SERVER:15672/api/queues/%2F";

WebClient webClient = new WebClient { Credentials = new NetworkCredential("MY_RABBITMQ_USERNAME", "MY_RABBITMQ_PASSWORD") };
string response = webClient.DownloadString(queuesUrl);

The username and password are the same as those you use to log into the RabbitMQ management console UI.

Response will be a JSON string with the list of queues, including their message counts, among other properties. (If you like, you can deserialize that JSON into a C# object using a library like Json.NET.)

The API documentation is installed along with the RabbitMQ management console and should be available on that server at http://MY_RABBITMQ_SERVER:15672/api .

查看更多
登录 后发表回答