2017-08-09 94 views
0

我需要设置队列中有多少条消息的上限。很显然,我需要知道队列中有多少物品。如何在不触及管理API或使用QueueDeclarePassive的情况下从c#客户端检查RabbitMQ队列中的消息数量?如何从c#客户端获得RabbitMQ队列大小?

+0

解释downvote? – Theyouthis

+0

回答你自己的问题没有错,但它必须是[实际问题](https://stackoverflow.com/help/how-to-ask),而不只是你的答案的介绍。阅读链接的“帮助其他人”部分。 –

+0

帮助他人重现问题? – Theyouthis

回答

2

下面是IModel对象上消息计数函数的示例。您不需要使用QueueDeclarePassive或向管理插件发出休息请求。这里有一个功能,它应该是。

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

对于文档: 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)