简体   繁体   中英

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

I wrote a python code using Time Trigger in Azure Function, that takes data from an api and sends it to Event Hub. When I'm executing the function, I'm getting the following error:

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.

My function.json looks as following:

{
  "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"
    }
  ]
}

The connection is defined in my local.settings.json, as well as in the configuration tab on Azure. I used the Connection string–primary key with manage, send and listen rights.

Is there anything that I've missed?

In Main function change your return type from None to str

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

Also, your connection property should have the name of the app setting that contains the connection string like this:

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

And then create an app setting named MyConnStringAppSetting and put your full connection string in there.

Refer here for complete example & SO Reference

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM