0

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

有什么我错过的吗?

4

1 回答 1

1

Main函数中将您的返回类型从更改Nonestr

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

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

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

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

请参阅此处以获取完整示例SO 参考

于 2021-12-24T06:24:19.807 回答