简体   繁体   English

Azure Function 服务总线批处理消息 - python

[英]Azure Function Servicebus batch process messages - python

I am implementing an azure function in python which is trying to batch process messages from a servicebus queue.我正在 python 中实现 azure function ,它试图批处理来自服务总线队列的消息。 I have modified the host.json file as follows:我修改了host.json文件如下:

{
    "version": "2.0",
    "serviceBus": {
        "batchOptions": {
            "maxMessageCount": 20,
            "operationTimeout": "01:00:00",
            "autoComplete": true
        }
    },
    "extensionBundle": {
        "id": "Microsoft.Azure.Functions.ExtensionBundle",
        "version": "[2.*, 3.0.0)"
    }
}

However, I am a bit lost as to how the messages will be received in my entry function in __init__.py .但是,对于如何在__init__.py中的条目 function 中接收消息,我有点迷茫。 Will it just be a list of messages and I can just loop through the messages as follows:它只是一个消息列表,我可以按如下方式遍历消息:

def main(messages: func.ServiceBusMessage):
    for msg in messages:
        json_obj = json.loads(msg.get_body().decode("utf-8"))
        print(json_obj)

Your binding configuration is not right, it is to be done in function.json properly.你的绑定配置不对,要在function.json中正确完成。 After your Azure function is configured as a Service Bus trigger, and bound correctly to the queue, then for each message generated, your function will get invoked once .在将 Azure function 配置为服务总线触发器并正确绑定到队列后,对于生成的每条消息,您的 function 将被调用一次 Your function will not get array of messages.您的 function 不会收到消息数组。 See the example code here to get more details.请参阅此处的示例代码以获取更多详细信息。

For regular standalone program to receive service bus messages as they are generated, see code in this page.有关在生成服务总线消息时接收服务总线消息的常规独立程序,请参阅本页中的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM