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?
Use multiple queues and consumers Queues are single-threaded in RabbitMQ, and one queue can handle up to about 50 thousand messages. You will achieve better throughput on a multi-core system if you have multiple queues and consumers and if you have as many queues as cores on the underlying node(s).
A RabbitMQ connection is based on protocols, is the base for having channels running and, as its names say, connects the server to the client. RabbitMQ client, which is connected to a channel listening to its queues in order to read the messages published on it.
Server-named Queues In AMQP 0-9-1, the broker can generate a unique queue name on behalf of an app. To use this feature, pass an empty string as the queue name argument: The same generated name may be obtained by subsequent methods in the same channel by using the empty string where a queue name is expected.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With