列出ServiceBus命名空间中的所有Azure

列出ServiceBus命名空间中的所有Azure

本文介绍了列出ServiceBus命名空间中的所有Azure Servicebus订阅的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将项目从WindowsAzure.ServiceBus迁移到新的Microsoft.Azure.Servicebus NuGet软件包.

I am migrating my project from the WindowsAzure.ServiceBus to the new Microsoft.Azure.Servicebus NuGet package.

问题是我找不到在servicebus命名空间中列出所有当前主题/订阅的方法.

The problem is that I cannot find a way to list all my current topics/subscriptions in my servicebus namespace.

这是我之前在旧的NuGet包中使用的代码段:

This is the piece of code I used before with the old NuGet package:

var namespaceManager = NamespaceManager.CreateFromConnectionString("ServiceBusConnectionString");

foreach (var topic in await namespaceManager.GetTopicsAsync())
{
    foreach (var subscription in await namespaceManager.GetSubscriptionsAsync(topic.Path))
    {
        //do something
    }
}
foreach (var queue in await namespaceManager.GetQueuesAsync())
{
    //do something
}

最新版本支持列出所有主题,订阅和队列.

The latest version has support for listing all topics, subscriptions and queues.

var managementClient = new ManagementClient("ServiceBusConnectionString");

foreach (var topic in await _managementClient.GetTopicsAsync())
{
    foreach (var subscription in await _managementClient.GetSubscriptionsAsync(topic.Path))
    {
        //do something
    }
}

推荐答案

Microsoft.Azure.Servicebus这是专注于queues & topics的下一代Service Bus .NET客户端库.您可以从Microsoft.Azure.Servicebus的更多信息. href ="https://github.com/Azure/azure-service-bus-dotnet" rel ="nofollow noreferrer"> github .

Microsoft.Azure.Servicebus This is the next generation Service Bus .NET client library that focuses on queues & topics.You could get more information about Microsoft.Azure.Servicebus from github.

如果需要管理操作,则新客户将不提供它.我建议您最好使用管理库,或者等到NamespaceManager的替代软件包推出为止.

If you need management opersations, the new client won't provide it. I recommend that you'd better use Management library or wait till a replacement package for NamespaceManager is out.

如果可以使用管理库,请使用以下命令演示代码以列出订阅.有关如何使用管理库的更多详细信息,您可以参考另一个.

If Management library is possible, you use the followingdemo code to list the subscription .For more details about how to use the Management Library, you could refer to another SO thread.

var credentials = SdkContext.AzureCredentialsFactory.FromFile(@"authpath");
var azure = Azure
            .Configure()
            .WithLogLevel(HttpLoggingDelegatingHandler.Level.Basic)
            .Authenticate(credentials)
            .WithDefaultSubscription();
var sbNameSpace = "service bus subscription";
var resoureGroup = "resourcegroup";
var topicName = "topicName"
var servicebus = azure.ServiceBusNamespaces.GetByResourceGroup(resoureGroup, sbNameSpace);
var topic = servicebus.Topics.GetByName(topicName);
var subscription = topic.Subscriptions.List();

这篇关于列出ServiceBus命名空间中的所有Azure Servicebus订阅的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 18:39