Reputation: 793
I am moving a old app from Msmq to RabbitMQ. The App uses MassTransit 2.10 and I need a function that returns the number of messages in queue for a specific message type.
In the current implementation there is this line of code that returns the message types:
var messages = MsmqEndpointManagement.New(endpoint.Address).MessageTypes();
Is it possible to replace this instruction with something similar when using RabbitMQ ?
Upvotes: 0
Views: 418
Reputation: 793
I have solved the issue using the following function, with EasyNetQ:
public static int GetMessageCount(string queueName)
{
IQueue queue;
IBus bus = getBusFromName(queueName);
if (queues.TryGetValue(queueName, out queue))
return (int)bus.Advanced.MessageCount(queue);
return 0;
}
the getBusFromName()
it's a function that retrieve the IBus
instance of the queue from a dictionary in which I store all the queues used by the software.
Upvotes: 0
Reputation: 43
With HareDu 2 Broker and Autofac APIs you can do the following:
var result = _container.Resolve<IBrokerObjectFactory>()
.Object<Queue>()
.GetAll()
.Select(x => x.Data)
.Select(x => new
{
QueueName = x.Name, x.TotalMessages
});
Upvotes: 0
Reputation: 33233
When moving to RabbitMQ, the management of queues is different. Since it's a broker (compared to MSMQ, which is a, well, different), it was designed with a separate management API and console. There are other libraries that can be used to get message counts, but not one that will get you the message types (since it would require reading every message to find the type - which is what that MSMQ method above is doing, btw).
I'd suggest looking at HareDu to manage your broker from the application/API.
Upvotes: 1