How do you get RabbitMQ queue size from c# client?

后端 未结 1 528
旧巷少年郎
旧巷少年郎 2021-01-24 06:31

I need to set an upper limit on how many messages can be in a queue. So obviously I need to know how many items are in a queue. How do you check the number of messages in a Rabb

相关标签:
1条回答
  • 2021-01-24 07:37

    Below is a example of the message count function on the IModel object. You do not need to use QueueDeclarePassive or make rest request to the managment plugin. There is a function right there where it should be.

    public uint GetMessageCount(string queueName)
    {
        using (IConnection connection = factory.CreateConnection())
        using (IModel channel = connection.CreateModel())
        {
            return channel.MessageCount(queueName);
        }
    }
    

    For documentation: 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)

    0 讨论(0)
提交回复
热议问题