我有 3 个 Azure Functions,我正在尝试编排它们。由于某种原因,事件函数没有被调用。
流程如下
F1(服务总线)-> F2(编排器)-> F3(事件)
F1
这是服务总线消息调用的函数。这工作正常。
import logging
import json
import azure.functions as func
import azure.durable_functions as df
async def main(msg: func.ServiceBusMessage, starter: str):
client = df.DurableOrchestrationClient(starter)
json_body = json.loads(msg.get_body().decode('utf-8'))
instance_id = await client.start_new('F2', None, json_body)
logging.info(f"Started orchestration with ID = '{instance_id}'")
配置是
{
"scriptFile": "__init__.py",
"bindings": [
{
"name": "msg",
"type": "serviceBusTrigger",
"direction": "in",
"queueName": "queueN",
"connection": "processConnectionString"
},
{
"name": "starter",
"type": "durableClient",
"direction": "in"
}
]
}
F2
这是协调器函数,也会被调用;但是,执行在 result = yield context.call_activity('F3', input_json)
Awaited
import logging
import json
import azure.functions as func
import azure.durable_functions as df
def orchestrator_function(context: df.DurableOrchestrationContext):
input_json = context.get_input()
result = yield context.call_activity('F3', input_json)
return result
main = df.Orchestrator.create(orchestrator_function)
配置是,
{
"scriptFile": "__init__.py",
"bindings": [
{
"name": "context",
"type": "orchestrationTrigger",
"direction": "in"
}
]
}
F3
应执行事件的最终函数。这不是从 F2
import logging
def main(input_json) -> str:
logging.info('Input processed message : %s', input_json)
return "Hello!"
配置是,
{
"scriptFile": "__init__.py",
"bindings": [
{
"name": "input_json",
"type": "activityTrigger",
"direction": "in"
}
]
}
使用 Azure Function 4
运行时和 Python 3.7
(由于遗留原因)。 更新:尝试使用Python 3.9
,但也不起作用
xxxxxx: Function 'F2 (Orchestrator)' awaited. IsReplay: False. State: Awaited. HubName: pyproxxxxx. AppName: py-proxxxxx. SlotName: Production. ExtensionVersion: 2.8.1. SequenceNumber: 11.
可能是什么问题?
最佳答案
当我尝试运行此代码时,我在终端读取时收到警告
[2022-11-07T20:56:23.947Z] The 'F3' function is in error: The binding name input_json is invalid. Please assign a valid name to the binding.
所以我认为问题在于参数名称 input_json
不是 Azure Functions 中的有效标识符。我通过将 input_json
重命名为 inputJson
(即将 Snake_case 改为 CamelCase)来让它工作。
因此,这一切让我怀疑问题在于 Azure Functions 运行时未正确解析 Snake_case,我认为这对于 Python 开发人员来说不是惯用的。我会将这个反馈传递给 Python 团队。
关于Python Durable Function 不调用 Activity,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74324378/