Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 949
null Avatar asked Mar 15 '23 20:03

null


2 Answers

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

like image 176
null Avatar answered Mar 18 '23 10:03

null


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);
}
like image 44
Andrew Chaa Avatar answered Mar 18 '23 08:03

Andrew Chaa