How do you get the message count for Azure Topic Subscription?

前端 未结 2 606
旧巷少年郎
旧巷少年郎 2020-12-31 10:43

Is there a way to get the current message count for an Azure topic subscription?

I see that the SubscriptionDescription class has a MessageCount property, but this

相关标签:
2条回答
  • 2020-12-31 11:03

    I found what I was looking for:

    var namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString);
    var subscriptionDesc = namespaceManager.GetSubscription(topicPath, subscriptionName);
    long messageCount = subscriptionDesc.MessageCount;
    
    0 讨论(0)
  • 2020-12-31 11:12

    The accepted answer is for when using the .NET Framework library with the namespace Microsoft.ServiceBus.Messaging (nuget package).

    For the .NET Standard library with the namespace Microsoft.Azure.ServiceBus (nuget package) the following code does the trick:

    var managementClient = new ManagementClient(connectionString);
    var runTimeInfo = await managementClient.GetSubscriptionRuntimeInfoAsync(topicPath, subscriptionName); 
    var messageCount = runTimeInfo.MessageCountDetails.ActiveMessageCount;
    

    See Microsoft.ServiceBus.Messaging vs Microsoft.Azure.ServiceBus for more details about the differences between the two libraries.

    0 讨论(0)
提交回复
热议问题