Azure Service Bus .NET SDK Deep Dive – Runtime Information

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 ManagementClient to create queues for example. Besides being able to create entities like queues, topics and subscriptions the management 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 dynamically spin up more entities according to number of messages within an entity.

To get information about the namespace we can simply call GetNamespaceInfoAsync.

var client = new ManagementClient(connectionString);
var namespaceInfo = await client.GetNamespaceInfoAsync();

which gives us

Namespace Information about 'nservicebustests'
Alias:
CreatedTime: 20.06.2017 15:21:44
MessagingSku: Standard
MessagingUnits: 0
ModifiedTime: 04.07.2019 13:43:17
Name: nservicebustests
NamespaceType: ServiceBus

For information about the queue we can call GetQueueRuntimeInfoAsync.

var inputQueueInfo = await client.GetQueueRuntimeInfoAsync(inputQueue);
Queue Information about 'queue'
AccessedAt: 22.03.2020 14:31:09
CreatedAt: 22.03.2020 14:31:07
MessageCount: 1
MessageCountDetails.ActiveMessageCount: 1
MessageCountDetails.DeadLetterMessageCount: 0
MessageCountDetails.ScheduledMessageCount: 0
MessageCountDetails.TransferDeadLetterMessageCount: 0
MessageCountDetails.TransferMessageCount: 0
Path: queue
SizeInBytes: 174
UpdatedAt: 22.03.2020 14:31:07

For more information about topics GetTopicRuntimeInfoAsync is our friend.

var topicInfo = await client.GetTopicRuntimeInfoAsync(topicName);

and this is what we have available:

TopicInformation Information about 'mytopic'
AccessedAt: 22.03.2020 14:31:09
CreatedAt: 22.03.2020 14:31:04
MessageCountDetails.ActiveMessageCount: 0
MessageCountDetails.DeadLetterMessageCount: 0
MessageCountDetails.ScheduledMessageCount: 0
MessageCountDetails.TransferDeadLetterMessageCount: 0
MessageCountDetails.TransferMessageCount: 0
Path: mytopic
SizeInBytes: 207
SubscriptionCount: 1
UpdatedAt: 22.03.2020 14:31:04

Last but not least we can query the subscription with GetSubscriptionRuntimeInfoAsync.

var subscriptionInfo = await client.GetSubscriptionRuntimeInfoAsync(topicName, subscriptionName);
Subscription Information about 'mysubscription'
AccessedAt: 22.03.2020 14:31:04
CreatedAt: 22.03.2020 14:31:04
MessageCount: 1
MessageCountDetails.ActiveMessageCount: 1
MessageCountDetails.DeadLetterMessageCount: 0
MessageCountDetails.ScheduledMessageCount: 0
MessageCountDetails.TransferDeadLetterMessageCount: 0
MessageCountDetails.TransferMessageCount: 0
SubscriptionName: mysubscription
TopicPath: mytopic
UpdatedAt: 22.03.2020 14:31:04

About the author

Daniel Marbach

1 comment

Recent Posts