新 NET 标准 Microsoft.Azure.ServiceBus 中 NamespaceManager.GetQueue.MessageCount 的等价物是什么?

What's the equivalent of NamespaceManager.GetQueue.MessageCount in the new NET Standard Microsoft.Azure.ServiceBus?

新 NET 标准中 NamespaceManager 的等价物是什么Microsoft.Azure.ServiceBus?

我用 WindowsAzure.ServiceBus 来做一些事情,比如计算队列中的消息...

var namespaceManager = NamespaceManager.CreateFromConnectionString(SbConnectionString);
var count = namespaceManager.GetQueue(queueName).MessageCount;

转移到新的 Microsoft.Azure.ServiceBus .NET Standard 库,但是虽然它有 类 像 QueueClient 和 TopicClient,但它没有任何 NamespaceManager

如何在新的 .NET Standard 库中进行消息计数?

你不能。

新的 API 不支持阅读消息计数。您必须使用 Azure Monitor API 来获取它们。

Reading Azure Service Bus Metrics 中阅读为什么会出现这种情况以及如何使用 Azure Monitor。

提供更新:

现在已在 Microsoft.Azure.ServiceBus.Management; 命名空间下实现并可用。

NamespaceManager 现在称为 ManagementClient 并且具有(大致)相同的可用端点。

这是 class itself as part of the pull request to merge it into the main repository

您可以读取队列消息计数:

var managementClient = new ManagementClient(connectionString);
(await managementClient.GetQueueRuntimeInfoAsync("name")).MessageCount;