【问题标题】:Azure Functions - Event Hub "A connection attempt failed" errorAzure Functions - 事件中心“连接尝试失败”错误
【发布时间】:2022-01-24 18:55:24
【问题描述】:

我使用 Azure Function 中的 Time Trigger 编写了一个 Python 代码,该代码从 api 获取数据并将其发送到 Event Hub。当我执行该函数时,我收到以下错误:

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 的配置选项卡中定义。 我使用了具有管理、发送和侦听权限的连接字符串-主键。

我有什么遗漏的吗?

【问题讨论】:

    标签: azure-functions azure-eventhub azure-eventhub-capture


    【解决方案1】:

    Main 函数中,将您的返回类型从None 更改为str

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

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

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

    然后创建一个名为 MyConnStringAppSetting 的应用设置,并将完整的连接字符串放入其中。

    complete example & SO Reference 参考这里

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-25
      • 2016-01-24
      • 1970-01-01
      • 2012-10-06
      • 1970-01-01
      • 2014-05-11
      • 2016-03-23
      相关资源
      最近更新 更多