0

I am new to azure SubscriptionClient, I am trying to get the total message count from azure SubscriptionClient with python.

0

2 Answers 2

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
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks a lot for this help @gaurav Mantri. It is working
Hi @gaurav Mantri, can you help with this question, --- stackoverflow.com/questions/60150669/…
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

Source: https://github.com/Azure/azure-sdk-for-python/blob/1709ec7898c87e4369f5324302f274f254857dc3/sdk/servicebus/azure-servicebus/samples/async_samples/mgmt_subscription_async.py

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.