Reputation: 2913
I am trying to get the number of messages still in the ServiceBus queue in Python.
I am able to receive messages but I can only find documentation to get the message count via the portal, CLI, or powershell, but not for the python SDK. Is there such a function or property?
from azure.servicebus import ServiceBusClient
with ServiceBusClient.from_connection_string(CONNECTION_STRING) as client:
with client.get_queue_receiver(QUEUE_NAME, max_wait_time=30) as receiver:
msgs = receiver.receive_messages(2)
for msg in msgs:
receiver.complete_message(msg)
number_of_retrieved_messages = len(msgs)
number_of_messages_still_in_queue = ?
Upvotes: 0
Views: 573
Reputation: 15551
Looking through the code of the Python SDK (the Azure Service Bus client library for Python), it appears that there's a ServiceBusAdministrationClient
that has a get_queue_runtime_properties
method.
queue_runtime_properties = await servicebus_mgmt_client.get_queue_runtime_properties(QUEUE_NAME)`
print("Message Count:", queue_runtime_properties.total_message_count)
Example found in async_samples/mgmt_queue_async.py
Implementation found in management/_management_client.py
Upvotes: 1