Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I iterate through queues using the RabbitMQ .NET Client?

Tags:

c#

rabbitmq

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?

like image 762
BobbyA Avatar asked Apr 10 '17 21:04

BobbyA


People also ask

Can RabbitMQ have multiple queues?

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).

How does RabbitMQ work in C#?

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.

How do I use RabbitMQ queues?

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.


1 Answers

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.

like image 101
istepaniuk Avatar answered Oct 06 '22 02:10

istepaniuk