Azure Functions - 事件中心 "A connection attempt failed" 错误

Azure Functions - Event Hub "A connection attempt failed" error

我使用 Azure 函数中的时间触发器编写了 python 代码,它从 api 获取数据并将其发送到事件中心。当我执行函数时,出现以下错误:

System.Private.CoreLib: Exception while executing function: Functions.TimerTrigger. Microsoft.Azure.WebJobs.Host: Error while handling parameter _binder after function returned:. System.Private.CoreLib: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

我的 function.json 看起来如下:

{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "name": "mytimer",
      "type": "timerTrigger",
      "direction": "in",
      "schedule": "0 */1 * * * *"
    },
    {
      "type": "eventHub",
      "name": "output",
      "eventHubName": "eventhub-af-project",
      "connection": "myconnection",
      "direction": "out"
    }
  ]
}

连接在我的 local.settings.json 以及 Azure 的配置选项卡中定义。 我使用了连接字符串——具有管理、发送和监听权限的主键。

有什么我遗漏的吗?

Main 函数中将您的 return 类型从 None 更改为 str

def main(mytimer: func.TimerRequest) -> str:

此外,您的 connection 属性 应具有包含连接字符串的应用设置名称,如下所示:

  "type": "eventHub",
  "name": "$return",
  "eventHubName": "sqlserverstreaming",
  "connection": "MyConnStringAppSetting",
  "direction": "out"

然后创建一个名为 MyConnStringAppSetting 的应用程序设置,并将完整的连接字符串放在那里。

参考这里 complete example &