gpt4 book ai didi

Azure Python 函数服务总线出站属性

转载 作者:行者123 更新时间:2023-12-03 00:26:13 24 4
gpt4 key购买 nike

我有一个 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/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com