Reputation: 2260
I'd like a way to iterate through existing queues on a rabbit server's virtual host, and output the number of messages in the queues, without hardcoding the queue names into my C# code.
Here's an example of getting the number of messages in a queue by hardcoding the queue value, using the RabbitMQ .NET Client:
using System;
using RabbitMQ.Client;
namespace RabbitMonitor
{
class Program
{
static void Main(string[] args)
{
var factory = new ConnectionFactory()
{
HostName = "<HostName>",
UserName = "<UserName>",
Password = "<Password>",
VirtualHost = "<VirtualHost>",
Port = 5672
};
var queueNameMessageCount = 0;
using (var connection = factory.CreateConnection())
using (var channel = connection.CreateModel())
{
queueNameMessageCount = channel.MessageCount("<QueueName>");
}
}
}
}
Is there a way I can get a collection of queues / queue names that are on a given virtual host, using the RabbitMQ .NET Client?
Related: is there a way for be to get a collection of virtual hosts/virtual host names on a server, using the RabbitMQ .NET Client?
Upvotes: 9
Views: 5454
Reputation: 4269
No, not really. At least not with the AMQP client, since the protocol does not provide a way to get such listing.
You can, however, use the RabbitMQ management plugin. It provides a REST API where you can gather this information.
Upvotes: 1