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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With