how to get list of service buses in a subscription or RG

Viewed 33

I am trying to use

var adminClient = new ServiceBusAdministrationClient(

to fetch some topics related data.

I see that ServiceBusAdministrationClient can be used for one SB. Is there a way to get a list of SBs in an Azure subscription or Resource Group so I can loop on it and do the same thing.

1 Answers

The SDK you would want to use is Microsoft.Azure.Management.ServiceBus.

To list Namespaces in a Subscription, the method you will need to use is NamespacesOperationsExtensions.ListAsync.

Similarly to list Namespaces in a Resource Group, the method you will need to use is NamespacesOperationsExtensions.ListByResourceGroupAsync

Your code would be something like (untested though):

var credentials = new DefaultAzureCredentials();

using (ServiceBusManagementClient client = new ServiceBusManagementClient(credentials))
{
    client.SubscriptionId = subscriptionId;
    var namespaces = client.Namespaces.ListAsync();
}
Related