I am new to azure SubscriptionClient, I am trying to get the total message count from azure SubscriptionClient with python.
Asked
Active
Viewed 569 times
2 Answers
1
Please try something like the following:
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

Gaurav Mantri
- 128,066
- 12
- 206
- 241
-
Thanks a lot for this help @gaurav Mantri. It is working – Code_rocks Feb 13 '20 at 09:40
-
Hi @gaurav Mantri, can you help with this question, --- https://stackoverflow.com/questions/60150669/how-to-read-all-message-from-azure-service-bus-topic-using-python – Code_rocks Feb 13 '20 at 09:54
0
This worked for me:
from azure.servicebus.aio import ServiceBusClient
from azure.servicebus.management import ServiceBusAdministrationClient
number_of_messages_in_subscription = 0
CONNECTION_STR = "<your_connection_string>"
with ServiceBusAdministrationClient.from_connection_string(CONNECTION_STR) as servicebus_mgmt_client:
global number_of_messages_in_subscription
TOPIC_NAME = "<your_topic_name>"
SUBSCRIPTION_NAME = "<your_subscription_name>"
get_subscription_runtime_properties = servicebus_mgmt_client.get_subscription_runtime_properties(TOPIC_NAME, SUBSCRIPTION_NAME)
number_of_messages_in_subscription = get_subscription_runtime_properties.active_message_count