【问题标题】:How to check the Azure Service Bus queue is empty?如何检查 Azure 服务总线队列是否为空?
【发布时间】:2018-04-26 19:02:26
【问题描述】:

我在我的应用程序中使用 azure 服务总线队列,这里我的问题是,有没有办法检查消息队列是否为空,以便我可以关闭我的容器和虚拟机以节省成本。如果有办法让我知道,最好是在 python 中。

谢谢

【问题讨论】:

  • 始终使用通用 [python] 标签,如果您的问题是特定于版本的,则仅使用特定于版本的标签。如果您不能同时满足两者,请始终使用通用 [python] 标签,如果只是为了让更多人关注您的问题

标签: python azure command-line-interface azure-servicebus-queues azure-queues


【解决方案1】:

为此,您可以使用Azure Service Bus Python SDK。您需要做的是使用get_queue 方法获取队列的属性,该方法将返回Queue 类型的对象。此对象通过message_count 属性公开消息总数。请注意,此计数将包括活动消息、死信队列消息等的计数。

这是一个示例代码:

from azure.servicebus import ServiceBusService, Message, Queue
bus_service = ServiceBusService(
    service_namespace='namespacename',
    shared_access_key_name='RootManageSharedAccessKey',
    shared_access_key_value='accesskey')
queue = bus_service.get_queue('taskqueue1')
print queue.message_count

适用于 Python 的 Azure 服务总线 SDK 的源代码可在 Github 上找到:https://github.com/Azure/azure-sdk-for-python/tree/master/azure-servicebus/azure/servicebus

【讨论】:

    猜你喜欢
    • 2021-09-01
    • 2017-02-25
    • 2020-09-20
    • 2015-07-18
    • 2011-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-17
    相关资源
    最近更新 更多