使用 python 从 azure SubscriptionClient 获取消息计数

Get message count from azure SubscriptionClient with python

我是 azure SubscriptionClient 的新手,我正在尝试使用 python 从 azure SubscriptionClient 获取消息总数。

请尝试如下操作:

from azure.servicebus import SubscriptionClient

conn_str = "Endpoint=sb://<service-bus-namespace-name>.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=access-key="
topic_name = "test"
subscription_name = "test"
client = SubscriptionClient.from_connection_string(conn_str, subscription_name, topic_name)
props = client.get_properties()
message_count = props['message_count']
print message_count