Muhammad Shafiq
Muhammad Shafiq

Reputation: 167

How to get list of topics in azure service

I am trying to get list of topics in service bus in .NET CORE App.

There is a way to get topics list using old service bus nuget package(WindowsAzure.ServiceBus) .

string connectionString = CloudConfigurationManager.GetSetting("Microsoft.ServiceBus.ConnectionString");
NamespaceManager nm = NamespaceManager.CreateFromConnectionString(connectionString);
IEnumerable<TopicDescription> topicList=nm.GetTopics();
        foreach(var td in topicList)
        {
            Console.WriteLine(td.Path);
        }

But we can't use this package (WindowsAzure.ServiceBus) in .NET Core applications.

.NET Core compatible package is Microsoft.Azure.ServiceBus and I did not find any help on the documentation page.

Upvotes: 2

Views: 1582

Answers (1)

Gaurav Mantri
Gaurav Mantri

Reputation: 136196

For listing topics (or queues), you will need to use Microsoft.Azure.ServiceBus.Management namespace.

using System;
using System.Threading.Tasks;
using Microsoft.Azure.ServiceBus.Management;

namespace SO68789585
{
    class Program
    {
        private const string ConnectionString = "Endpoint=sb://namespacename.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=sharedaccesskey";
        static async Task Main(string[] args)
        {
            var managementClient = new ManagementClient(ConnectionString);
            var topics = await managementClient.GetTopicsAsync();
            foreach (var topic in topics)
            {
                Console.WriteLine(topic.Path);//Prints topic name
            }
        }
    }
}

Upvotes: 4

Related Questions