仍在 azure servicebus 队列中的消息数
Number of messages still in azure servicebus queue
我正在尝试获取仍在 Python 的 ServiceBus 队列中的消息数。
我可以接收消息,但我只能找到 documentation to get the message count via the portal, CLI, or powershell,但不能找到 python SDK。有这样的功能还是属性?
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 = ?
查看 Python SDK(Azure Service Bus client library for Python)的代码,似乎有一个 ServiceBusAdministrationClient
有一个 get_queue_runtime_properties
方法。
queue_runtime_properties = await servicebus_mgmt_client.get_queue_runtime_properties(QUEUE_NAME)`
print("Message Count:", queue_runtime_properties.total_message_count)
在 async_samples/mgmt_queue_async.py
中找到的示例
management/_management_client.py
中的实现
我正在尝试获取仍在 Python 的 ServiceBus 队列中的消息数。
我可以接收消息,但我只能找到 documentation to get the message count via the portal, CLI, or powershell,但不能找到 python SDK。有这样的功能还是属性?
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 = ?
查看 Python SDK(Azure Service Bus client library for Python)的代码,似乎有一个 ServiceBusAdministrationClient
有一个 get_queue_runtime_properties
方法。
queue_runtime_properties = await servicebus_mgmt_client.get_queue_runtime_properties(QUEUE_NAME)`
print("Message Count:", queue_runtime_properties.total_message_count)
在 async_samples/mgmt_queue_async.py
中找到的示例
management/_management_client.py