Check RabbitMQ queue size from client

后端 未结 9 1129
终归单人心
终归单人心 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 20:59

    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 .

提交回复
热议问题