当我使用 Azure 服务总线队列作为触发器托管在 Azure 上时,无法触发我的 Azure 函数。它在本地运行时工作正常,但在远程运行时则不然。
function.json
{
"scriptFile": "__init__.py",
"bindings": [
{
"name": "msg",
"type": "serviceBusTrigger",
"direction": "in",
"AzureWebJobsStorage": "AzureWebJobsStorage",
"queueName": "selectivitycalculation",
"connection": "AzureServiceBusConnectionString"
}
]
}
local.settings.json
{
"IsEncrypted": false,
"Values": {
"FUNCTIONS_WORKER_RUNTIME": "python",
"AzureWebJobsStorage": XXXXXX,
"AzureServiceBusConnectionString": XXXXXXX
}
}
主机.json
{
"version": "2.0",
"extensions": {
"serviceBus": {
"prefetchCount": 100,
"messageHandlerOptions": {
"autoComplete": false,
"maxConcurrentCalls": 32,
"maxAutoRenewDuration": "00:55:00"
}
}
},
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[1.*, 2.0.0)"
},
"functions": [ "SelectivityCalculation" ],
"logging": {
"fileLoggingMode": "debugOnly",
"logLevel": {
"Function.MyFunction": "Information",
"default": "None"
},
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"maxTelemetryItemsPerSecond" : 20
}
}
}
}
__init__.py
import azure.functions as func
import logging
import sys
from .azure_functions_controller import selectivity_callback
def main(msg: func.ServiceBusMessage):
logger.info('Python ServiceBus queue trigger processed message.')
print('working')
selectivity_callback(msg.get_body())
文件夹结构
Calculator
| - __app__
| | - SelectivityCalculation
| | | - __init__.py
| | | - azure_functions_controller.py
| | | - functions.json
| | - SharedCode
| | | - ...
| | - host.json
| | - bin
我的开发环境如下:
1) Windows 10 专业版 2)VS代码1.41.1 3) Azure Functions CLI 2.7.1948 4)Python 3.7.4
最佳答案
您的配置问题是:
"autoComplete": false,
autocomplete=false is only supported for C# ,所以在 Python 中,不可能以交互方式发送死信消息。
换句话说,这意味着使消息成为死信的唯一方法是在处理消息时引发异常。
关于python-3.x - 服务总线未在 Azure 上触发,在本地工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59650465/