2017-02-01 12:51:32
0
I am trying to fetch the total number of consumers for a particular queue in RabbitMQ. I wrote my code in C# using RabbitMQ client for .Net.
string user = ConfigurationManager.AppSettings[“rmq_user”];
string pword = ConfigurationManager.AppSettings[“rmq_pass”];
string port = ConfigurationManager.AppSettings[“rmq_port”];
string host = new Uri(ConfigurationManager.AppSettings[“rest_api_url”]).Host;
var factory = new ConnectionFactory();
factory.Uri = “amqp://” + user + “:” + pword + “@” + host + “:” + port;
using (var connection = factory.CreateConnection())
{
using (var channel = connection.CreateModel())
{
var consumerCount = ((RabbitMQ.Client.Impl.ModelBase)(channel)).m_consumers;
}
}
I am getting var consumerCount = ((RabbitMQ.Client.Impl.ModelBase)(channel)).m_consumers; as 0. However I can see the consumers in the RabbitMQ web and I have made sure that the consumers do exist in that queue.
Is this the correct way to get the consumer count or I am doing something wrong I know this can be done using RabbitMQ admin but I need to do it in C#.
Please let me know if I can give some more details.