我已经使用 terraform 创建了一个 Azure 服务总线队列,它已部署并正常工作。 我想为队列添加重试延迟。 我在 Python V2 模型中添加了以下行,但部署后它会中断,并且我的函数从 Azure 函数选项卡中消失
@app.retry(strategy="fixed_delay", delay_interval="00:00:10")
@app.service_bus_queue_trigger(arg_name="azservicebus", queue_name="publish-queue", connection="SERVICE_BUS_CONNECTION",
)
def publish_der(azservicebus: func.ServiceBusMessage):
"""Service bus trigger which receives data from API"""
//implementation goes here
为 Python v2 添加重试的正确方法是什么?
要在 Azure Function Service 总线 V2 模型中使用重试选项,您需要在本地的
host.json
中使用重试选项:
{
"version": "2.0",
"retry": {
"strategy":"fixedDelay",
"maxRetryCount": 5,
"delayInterval":"00:00:30"
},
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
}
}
},
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[4.*, 5.0.0)"
}
}
我的
functionapp.py
:
import azure.functions as func
import logging
app = func.FunctionApp()
@app.service_bus_queue_trigger(arg_name="azservicebus", queue_name="mysbqueue",
connection="testjkafka_SERVICEBUS")
def servicebus_queue_trigger(azservicebus: func.ServiceBusMessage):
raise Exception("Simulated failure")
logging.info('Python ServiceBus Queue trigger processed a message: %s',
azservicebus.get_body().decode('utf-8'))
然后当我部署时我可以看到我的功能: