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?
The .NET Standard client (
Microsoft.Azure.ServiceBus
) is deliberately not providing management operations. It states that management operations should not be performed at run time. Management operations are extremely slow.Yes, it is possible.
Instead of the
NamespaceManager
that was available with the old client (WindowsAzure.ServiceBus
), there's a ServiceBus management library (Microsoft.Azure.Management.ServiceBus.Fluent
)You will need to do the following:
ServiceBusManager
ServiceBusManager.Namespaces
ServiceBusManager.Namespaces.Queues
/ServiceBusManager.Namespaces.Topics
. For subscription you'll need to locate one viaITopic
object.IQueue
,ITopic
, orISubscription
), you'll be able to access the message counts.I'm not a big fan of this approach. Rather than each developer reinventing this wheel, Azure Service Bus team should have provided a helper library to replace
NamespaceManger
. You can always raise an issue or vote for an issue that was closed.Management operations were introduced back in version 3.1.1 with pull request #481.