Azure Servicebus - 获取 python 中的所有可用主题
Azure Servicebus - get all available topics in python
我有一个 Azure 服务总线,想根据我的连接字符串检索所有可用的主题。
在 Microsoft 文档中,我能够看到有一个 "GetTopics" function for C# - is there something similar available within the Python SDK? I cant find anything in the source code of the azure-sdk-for-python...
CONNECTION_STR = "XXX"
servicebus_client = ServiceBusClient.from_connection_string(conn_str=CONNECTION_STR, logging_enable=True)
servicebus_client.gettopics() # function does not exist in Python
澄清:我不知道主题名称,想知道 ServiceBusClient 上有哪些主题名称!
您要找的方法是list_topics
in ServiceBusAdministrationClient
class.
这是从 here
中获取的示例代码:
import os
import uuid
import datetime
from azure.servicebus.management import ServiceBusAdministrationClient
CONNECTION_STR = os.environ['SERVICE_BUS_CONNECTION_STR']
def list_topics(servicebus_mgmt_client):
print("-- List Topics")
for topic_properties in servicebus_mgmt_client.list_topics():
print("Topic Name:", topic_properties.name)
print("")
with ServiceBusAdministrationClient.from_connection_string(CONNECTION_STR) as servicebus_mgmt_client:
list_topics(servicebus_mgmt_client)
我有一个 Azure 服务总线,想根据我的连接字符串检索所有可用的主题。
在 Microsoft 文档中,我能够看到有一个 "GetTopics" function for C# - is there something similar available within the Python SDK? I cant find anything in the source code of the azure-sdk-for-python...
CONNECTION_STR = "XXX"
servicebus_client = ServiceBusClient.from_connection_string(conn_str=CONNECTION_STR, logging_enable=True)
servicebus_client.gettopics() # function does not exist in Python
澄清:我不知道主题名称,想知道 ServiceBusClient 上有哪些主题名称!
您要找的方法是list_topics
in ServiceBusAdministrationClient
class.
这是从 here
中获取的示例代码:
import os
import uuid
import datetime
from azure.servicebus.management import ServiceBusAdministrationClient
CONNECTION_STR = os.environ['SERVICE_BUS_CONNECTION_STR']
def list_topics(servicebus_mgmt_client):
print("-- List Topics")
for topic_properties in servicebus_mgmt_client.list_topics():
print("Topic Name:", topic_properties.name)
print("")
with ServiceBusAdministrationClient.from_connection_string(CONNECTION_STR) as servicebus_mgmt_client:
list_topics(servicebus_mgmt_client)