我有一个 azure python 函数:它由 HTTP 触发,使用 HTTP 响应进行响应,并将消息放入 Azure 服务总线队列中。
Function.json:用于出站 Azure 服务总线
{
"type": "serviceBus",
"connection": "ServiceBus",
"name": "outputMessage",
"queueName": "testqueue",
"accessRights": "send",
"direction": "out"
}
我的功能是
def main(req: func.HttpRequest, outputMessage: func.Out[func.ServiceBusMessage]) -> str:
我收到以下错误: 结果:失败 异常:FunctionLoadError:无法加载 HttpTrg 函数:function.json“serviceBus”中的 outputMessage 绑定(bind)类型与其 Python 注释“ServiceBusMessage”不匹配
问题: 1. Azure 服务总线出站的 python 注释应该是什么?
def main( , outputMessage: func.Out[func.ServiceBusMessage])
我可以为 Azure 服务总线保留 -> str 吗?
func.Out[func.ServiceBusMessage]) -> str
我可以使用 set 方法发送消息,例如:
outputMessage.set(text)
“要生成多个输出,请使用 azure.functions.Out 接口(interface)提供的 set() 方法为绑定(bind)分配一个值” -> 这可行吗?
谢谢 桑迪普
最佳答案
另一个example能够使用 python 将输出绑定(bind)到服务总线:
// function.json
{
"scriptFile": "__init__.py",
"bindings": [
{
"authLevel": "function",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get",
"post"
]
},
{
"type": "http",
"direction": "out",
"name": "$return"
},
{
"type": "serviceBus",
"direction": "out",
"connection": "AzureWebJobsServiceBusConnectionString",
"name": "msg",
"queueName": "outqueue"
}
]
}
.
# __init__.py
import azure.functions as func
def main(req: func.HttpRequest, msg: func.Out[str]) -> func.HttpResponse:
msg.set(req.get_body())
return 'OK'
关于Azure Python 函数服务总线出站属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57313773/