如何使用Python从Azure Service Bus主题读取所有消息? [英] How to read all message from Azure Service Bus topic using Python?

查看:250
本文介绍了如何使用Python从Azure Service Bus主题读取所有消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用python从azure服务总线中读取所有消息.目前,它仅提取一条消息.

I want to read all messages from azure service bus using python. Currently it fetch only one message.

from azure.servicebus.control_client import ServiceBusService, Message, Topic, Rule, DEFAULT_RULE_NAME

    bus_service = ServiceBusService(
        service_namespace='<NameSpace>',
        shared_access_key_name='<KeyName>',
        shared_access_key_value='<ConnectionString>')

msg = bus_service.receive_subscription_message('topic', 'msglist', peek_lock=True)
print(msg.body)

如何使用python 3从主题中批量获取所有消息

How can I get all the message in bulk from the topic with python 3

推荐答案

这可以通过使用此样本,其中展示了如何获取该对象进行订阅.

This is possible by using a Receiver object which supports batch operations. Refer this sample which showcases how to get this object for a subscription.

要确保收到大量消息,必须设置 max_batch_size自变量fetch_next() 相同.

To guarantee you get batches of messages, you have to set the prefetch argument of get_receiver() to your batch size and consequently the max_batch_size argument of fetch_next() to the same.

这篇关于如何使用Python从Azure Service Bus主题读取所有消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆