如何在Python函数中使用Azure函数命令输出绑定?
我正在尝试设置Azure函数,以从EventHub“ A”接收消息,然后根据使用功能绑定的输入消息将消息发送到EventHub“ B”或C的一个。
Azure函数支持EventHub的触发和输出绑定,但是,我不知道如何正确设置势在必行的输出绑定。
到目前为止,这是我的函数。 tabs =过程中%2cfunctionsv2%2cextensionv5& pivots =编程语言 - 语言 - python#usage'rel =“ nofollow noreferrer”> docs :
{
"scriptFile": "__init__.py",
"bindings": [
{
"name": "event",
"type": "eventHubTrigger",
"direction": "in",
"eventHubName": "A",
"consumerGroup": "myConsumerGroup",
"connection": "aConnectionString"
},
{
"type": "eventHub",
"name": "B",
"eventHubName": "B",
"connection": "bConnectionString",
"direction": "out"
},
{
"type": "eventHub",
"name": "C",
"eventHubname": "C",
"connection": "cConnectionString",
"direction": "out"
}
]
}
import logging
import azure.functions as func
def main(event: func.EventHubEvent, B: func.Out, C: func.Out):
logging.info(f'########################################')
logging.info(f'Function triggered to process a message:')
logging.info(f' EnqueuedTimeUtc = {event.enqueued_time}')
logging.info(f' SequenceNumber = {event.sequence_number}')
logging.info(f' Offset = {event.offset}')
logging.info(f'----------------------------------------')
logging.info(f' Metadata: ')
for key in event.metadata:
logging.info(f' key {key} = {event.metadata[key]}')
logging.info(f' Body = {event.get_body().decode()}')
logging.info(f'----------------------------------------')
logging.info(f'B={B}')
logging.info(f'C={C}')
logging.info(f'########################################')
带有输出bindings and func.unc.unc.ut and func.ut and func.out tymed tym the函数,azure,azure功能不会触发。没有,确实如此。
任何帮助将不胜感激。
I am trying to setup an azure function to receive messages from EventHub "A", then send messages to one of eventHub "B" or C depending on the input message using function bindings.
Azure functions supports both trigger and output bindings for the EventHub, however, i can't figure out how to setup imperative output bindings properly.
Here are my function.json and python function code so far, inspired by the docs:
{
"scriptFile": "__init__.py",
"bindings": [
{
"name": "event",
"type": "eventHubTrigger",
"direction": "in",
"eventHubName": "A",
"consumerGroup": "myConsumerGroup",
"connection": "aConnectionString"
},
{
"type": "eventHub",
"name": "B",
"eventHubName": "B",
"connection": "bConnectionString",
"direction": "out"
},
{
"type": "eventHub",
"name": "C",
"eventHubname": "C",
"connection": "cConnectionString",
"direction": "out"
}
]
}
import logging
import azure.functions as func
def main(event: func.EventHubEvent, B: func.Out, C: func.Out):
logging.info(f'########################################')
logging.info(f'Function triggered to process a message:')
logging.info(f' EnqueuedTimeUtc = {event.enqueued_time}')
logging.info(f' SequenceNumber = {event.sequence_number}')
logging.info(f' Offset = {event.offset}')
logging.info(f'----------------------------------------')
logging.info(f' Metadata: ')
for key in event.metadata:
logging.info(f' key {key} = {event.metadata[key]}')
logging.info(f' Body = {event.get_body().decode()}')
logging.info(f'----------------------------------------')
logging.info(f'B={B}')
logging.info(f'C={C}')
logging.info(f'########################################')
With the output bindings and func.Out typed params in the function, the azure function doesn't trigger. Without, it does.
Any help would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我使用Azurite Vscode扩展名来弄清楚它:有几个问题:
b
的输出绑定名称
中有一个下划线。这使得名字无效。func.out
是一种通用类型,需要注释类型:例如:func.out [str]
I figured it out using the Azurite vscode extension: there were several issues:
name
forB
had an underscore in it. that makes the name invalid.func.Out
is a generic type, and the type needs to be annotated: eg:func.Out[str]