简体   繁体   中英

How to retrieve all topics from Azure Bus Service?

I have a Azure service bus containing 12 Topics. I am making a scale-able application where if the number of topics isreduced or increased , the application should use connectionString to get all topics names for that service bus.

How can I get all topics name from a particular Azure service bus?

Please provide code sample that retrieve topic list from a particular Azure service bus.

Thanks @RyanChu for correct answer.

Here is the required code segment that implements above requirement ,

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);
        }

For more details , refer NamespaceManager.GetTopics() Documentation

Microsoft.Azure.Servicebus is a package for .NET Core. The syntax is slightly different. This is a piece of code in my project.

var managementClient = new ManagementClient(_connectionString);
var topicDescriptions = new List<TopicDescription>();

for (int skip = 0; skip < 1000; skip += 100)
{
    var topics = await managementClient.GetTopicsAsync(100, skip);
    if (!topics.Any()) break;

    topicDescriptions.AddRange(topics);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM