Azure Function 应用程序:Microsoft.Azure.WebJobs.EventHubs:值不能为空。(参数'receiverConnectionString')

Mer*_*shi 2 python function azure

我遵循以下结构,但在上传功能应用程序后,我遇到错误:

https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-event-iot-trigger?tabs=python

错误:

函数(转换/EventHubTrigger1)错误:Microsoft.Azure.WebJobs.Host:错误索引方法“Functions.EventHubTrigger1”。Microsoft.Azure.WebJobs.EventHubs:值不能为空。(参数'receiverConnectionString')。会话 ID:cb179cdab03c4e8c80f1f82d9da9d143

时间戳:2020-03-11T15:55:55.575Z

在此处输入图片说明


Function.json :
{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "type": "eventHubTrigger",
      "name": "event",
      "direction": "in",
      "eventHubName": "iothub-ehub-neas-hub-xxx-xxxx",
      "connection": "Endpoint=sb://xxxxxxxxxxxx.servicebus.windows.net/;SharedAccessKeyName=iothubowner;SharedAccessKey=xxxxxxxxxxx=;EntityPath=iothub-ehub-neas-hub-xxxxxx-856659355a",
      "cardinality": "many",
      "consumerGroup": "$Default"
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)

Mar*_*ton 5

您需要将端点信息放在 local.settings.json 中并从 function.json 中引用它。XXXX 只是为了显示更多。连接字符串是您在事件中心门户中获得的内容。我在 node.js 中设置了同样的问题。

本地设置.json

{
  "IsEncrypted": false,
  "Values": {
    "FUNCTIONS_WORKER_RUNTIME": "node",
    "AzureEventHubConnectionString": "Endpoint=XXXX",
    "AzureWebJobsStorage": "DefaultEndpointsProtocol=XXXX"
  }
}
Run Code Online (Sandbox Code Playgroud)

然后在你的 function.json

{
  "bindings": [
    {
      "type": "eventHubTrigger",
      "name": "IoTHubMessages",
      "direction": "in",
      "eventHubName": "<event hub name you have>",
      "connection": "AzureEventHubConnectionString",
      "cardinality": "many",
      "consumerGroup": "$Default"
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)

这将摆脱receiverConnectionString 错误。


sil*_*ent 1

在该connection字段中,您不要输入连接字符串本身。相反,您输入应用程序设置的名称(即密钥) 。在此您输入连接字符串。