How to read all message from Azure Service Bus topic using Python?

自古美人都是妖i 提交于 2020-03-25 19:22:49

问题


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)

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


回答1:


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.

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.



来源:https://stackoverflow.com/questions/60150669/how-to-read-all-message-from-azure-service-bus-topic-using-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!