[英]How to retrieve all topics from Azure Bus Service?
I have a Azure service bus containing 12 Topics.我有一个包含 12 个主题的 Azure 服务总线。 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.我正在制作一个可扩展的应用程序,如果主题数量减少或增加,应用程序应使用
connectionString
获取该服务总线的所有主题名称。
How can I get all topics name from a particular Azure service bus?如何从特定 Azure 服务总线获取所有主题名称?
Please provide code sample that retrieve topic list from a particular Azure service bus.请提供从特定 Azure 服务总线检索主题列表的代码示例。
Thanks @RyanChu for correct answer.感谢@RyanChu 的正确答案。
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有关更多详细信息,请参阅NamespaceManager.GetTopics() 文档
Microsoft.Azure.Servicebus is a package for .NET Core. Microsoft.Azure.Servicebus 是 .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);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.