我在Python中创建了azure函数,它从事件中心触发,并在计算后输出到两个给定的事件中心之一。我尝试了以下方法,但不起作用:
def main(event: func.EventHubEvent, eh1: func.Out[func.EventHubEvent], eh2: func.Out[func.EventHubEvent]):
if condition: eh1.set(ev1)
else: eh2.set(ev2)第一个(事件)充当事件中心触发器,其他两个是目标事件中心。我不能使用$return,因为我打算有多个输出。给定的错误:
11/05/2020 08:10:54] Worker failed to function id 84b68627-224b-4626-93cb-xxxxxxx.
[11/05/2020 08:10:54] Result: Failure
[11/05/2020 08:10:54] Exception: FunctionLoadError: cannot load the EventHubTriggerFunction function: type of eh1 binding in function.json "eventHub" does not match its Python annotation "EventHubEvent"
[11/05/2020 08:10:54] Stack: File "/usr/local/Cellar/azure-functions-core-tools/2.7.2508/workers/python/3.7/OSX/X64/azure_functions_worker/dispatcher.py", line 246, in _handle__function_load_request
[11/05/2020 08:10:54] function_id, func, func_request.metadata)
[11/05/2020 08:10:54] File "/usr/local/Cellar/azure-functions-core-tools/2.7.2508/workers/python/3.7/OSX/X64/azure_functions_worker/functions.py", line 216, in add_function
[11/05/2020 08:10:54] f'type of {param.name} binding in function.json 'Function.json中的相应部分:
{
"type": "eventHub",
"name": "eh1",
"eventHubName": "EventHubName",
"connection": "ConnectionSetting",
"direction": "out"
}作为最后的手段,我使用了普通的客户端,并将其连接到两个事件中心,但这感觉更像是一个老生常谈的解决方案。如果我遗漏了什么,请告诉我。
发布于 2020-05-12 00:21:45
好的,我找到了一个可行的解决方案。我不确定这是否是理想的,但它确实有效。问题是"func.Outfunc.EventHubEvent“和"eventHub”之间的类型不匹配。因此,我将其更改为func.Outstr,现在我将对象转换为字符串
def main(event: func.EventHubEvent, eh1: func.Out[str], eh2: func.Out[str]):
ev1 = {"field1":"Sample field", "field2":"Sample field2"}
ev2 = {"field1":"field1Value", "field2":"field2Value", "paths":[
"path/to/file/1",
"path/to/file/2",
"path/to/file/3"
]}
logging.info("Sending events")
eh1.set(json.dumps(ev1))
eh2.set(json.dumps(ev2))https://stackoverflow.com/questions/61725194
复制相似问题