简体   繁体   English

如何从C#客户端获取RabbitMQ队列大小?

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

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 RabbitMQ queue from the c# client without hitting the management API or using QueueDeclarePassive? 如何在不点击管理API或不使用QueueDeclarePassive的情况下从c#客户端检查RabbitMQ队列中的消息数?

Below is a example of the message count function on the IModel object. 下面是IModel对象上的消息计数功能的示例。 You do not need to use QueueDeclarePassive or make rest request to the managment plugin. 您无需使用QueueDeclarePassive或向管理插件提出休息请求。 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) 有关文档: 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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM