Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET Core Azure servicebusqueue number of messages

I am currently working on a .NET Core project where I use the Microsoft.Azure.Servicebus version 1.0 NuGet package found here: https://github.com/Azure/azure-service-bus

The problem I have is that I haven't found any method to get a queue's number of active messages. This used to be pretty easy with .NET framework using the ServicebusNamespace.NamespaceManager, referring to a queue and use the .ActiveMessageCount.

Is this possible in some other way in this library with .NET Core 1.1?

like image 284
Nicklas Lundgren Avatar asked Dec 14 '22 20:12

Nicklas Lundgren


1 Answers

It is now possible using the latest version of the Service Bus library (3.1.1):

using Microsoft.Azure.ServiceBus;
using Microsoft.Azure.ServiceBus.Management;

var client = new ManagementClient(connectionString);
var queue = await client.GetQueueRuntimeInfoAsync(queuePath);
var counts = queue.MessageCountDetails;

var subs = await client.GetSubscriptionRuntimeInfoAsync(topic, subscription);
var countForThisSubscription = subs.MessageCount;  //// (Comes back as a Long.)
like image 78
malafreniere Avatar answered Mar 16 '23 03:03

malafreniere