3
votes

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.

2
namespaceManager.GetTopics()?Ryan Chu
@RyanChu Please put your comment as an answer.Gaurav Mantri

2 Answers

5
votes

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

1
votes

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