Shows how to query runtime information using the management client, for more posts in this series go to Contents.
Quite early in this series I introduced the ServiceBusAdministrationClient to create queues for example. Besides being able to create entities like queues, topics and subscriptions, the administration client provides the capability of querying runtime information from namespaces, queues, topics and subscriptions. The ability to query runtime information is quite handy for diagnostics purposes, check if messages have been dead lettered or if you need to get fancy to dynamically spin up more entities according to number of messages within an entity.
To get information about the namespace, we can simply call GetNamespacePropertiesAsync.
var client = new ServiceBusAdministrationClient(connectionString);
var namespaceInfo = await client.GetNamespacePropertiesAsync();
which gives us
Namespace Information about 'nservicebustests'
Alias:
CreatedTime: 6/20/2017 1:21:44 PM +00:00
MessagingSku: Standard
MessagingUnits: 0
ModifiedTime: 8/5/2020 4:45:53 PM +00:00
Name: nservicebustests
MessagingUnits: 0
For information about the queue we can call GetQueueRuntimePropertiesAsync.
var inputQueueInfo = await client.GetQueueRuntimePropertiesAsync(inputQueue);
Queue Information about 'queue'
AccessedAt: 6/25/2021 4:11:58 PM +00:00
CreatedAt: 6/25/2021 4:11:57 PM +00:00
TotalMessageCount: 1
ActiveMessageCount: 1
DeadLetterMessageCount: 0
ScheduledMessageCount: 0
TransferDeadLetterMessageCount: 0
TransferMessageCount: 0
Name: queue
SizeInBytes: 177
UpdatedAt: 6/25/2021 4:11:57 PM +00:00
For more information about topics GetTopicRuntimePropertiesAsync is our friend.
var topicInfo = await client.GetTopicRuntimePropertiesAsync(topicName);
and this is what we have available:
TopicInformation Information about 'mytopic'
AccessedAt: 6/25/2021 4:11:58 PM +00:00
CreatedAt: 6/25/2021 4:11:55 PM +00:00
ScheduledMessageCount: 0
SubscriptionCount: 1
Name: mytopic
SizeInBytes: 210
SubscriptionCount: 1
UpdatedAt: 6/25/2021 4:11:55 PM +00:00
Last but not least we can query the subscription with GetSubscriptionRuntimePropertiesAsync.
var subscriptionInfo = await client.GetSubscriptionRuntimePropertiesAsync(topicName, subscriptionName);
Subscription Information about 'mysubscription'
AccessedAt: 6/25/2021 4:11:55 PM +00:00
CreatedAt: 6/25/2021 4:11:55 PM +00:00
TotalMessageCount: 1
TotalMessageCount: 1
ActiveMessageCount: 1
DeadLetterMessageCount: 0
ScheduledMessageCount: 0
TransferDeadLetterMessageCount: 0
TransferMessageCount: 0
SubscriptionName: mysubscription
TopicName: mytopic
UpdatedAt: 6/25/2021 4:11:55 PM +00:00
[…] Azure Service Bus .NET SDK Deep Dive – Runtime Information (Daniel Marbach) […]