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

标签 azure azure-functions

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

    相关文章:

    linux - '甲骨文 :Oracle-Linux:7. 0:最新'

    使用 DeployIfNotExists 策略对私有(private) dns 区域组进行 Azure Terraformignore_changes

    azure-functions - 创建 azure 函数应用程序后如何更改运行时堆栈

    python - Azure 函数 - Python - Visual Studio Code

    azure - 检查 Azure Functions 运行的环境

    .net - Azure 事件中心同步机制

    python - Azure B2C : Error in the callback after the edit profile when it tries to get a new token

    java - OpenSAML 如何检查 SAML 响应(签名/证书)是否确实来 self 的 IDP?

    Azure 函数 - 超出 HTTP 触发器请求长度

    azure - 使用 Az CLI/PowerShell 从 Function App 重新导入 API 管理 API