2

I want to know there are too many service bus messages in my queue and if need be replay(dead-lettered messages) them. I am currently able to peek and replay the messages but I have no clue on how to get the active/dead-lettered-message count. I'm basically looking for the python equivalent of this powershell command.

az servicebus queue show --resource-group myresourcegroup \
    --namespace-name mynamespace \
    --name myqueue \
    --query countDetails

There's documentation for this on powershell but I wasn't able to find anything for python. Can someone. Can someone kindly help me with this?

2 Answers 2

1

You can use Azure Service Bus Python SDK.

First get the properties of a queue using get_queue method which will contain property called message_count which will give you the count of messages.

queue = bus_service.get_queue('queue1')
print queue.message_count
Sign up to request clarification or add additional context in comments.

2 Comments

I don't find the get_queue method anywhere. Can you kindly help with the same? I see a get_queue_sender()
The get_queue method is on the ServiceBusAdministrationClient under the azure.servicebus.management namespace. You can find the total message count in the queue by following this sample here: github.com/Azure/azure-sdk-for-python/blob/….
1

Can't add as a comment, other answer is correct wrt Azure Service Bus Python SDK however code is slightly different

Sample code:

with azure.servicebus.management.ServiceBusAdministrationClient.from_connection_string(CONNECTION_STR) as client:
 print(client.get_queue_runtime_properties(QUEUE_NAME).active_message_count)
  

Key part is using the get_queue_runtime_properties and not just get_queue

(May be the case that the SDK has updated since)

Hope this helps someone!

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.