List all Azure servicebus subscriptions in a ServiceBus namespace

孤人 提交于 2020-01-04 09:03:59

问题


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

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

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
}

Edit: 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
    }
}

回答1:


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.

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 following demo 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();


来源:https://stackoverflow.com/questions/49625955/list-all-azure-servicebus-subscriptions-in-a-servicebus-namespace

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!