Search code examples
python-3.xazureazureservicebusazure-servicebus-topicsazure-servicebus-subscriptions

Get message count from azure SubscriptionClient with python


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


Solution

  • 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