【Azure 应用服务】Azure Function Python函数部署到Azure后遇见 Value cannot be null. (Parameter 'receiverConnectionString') 错误 - LuBu0505/My-Code GitHub Wiki

问题描述

使用VS Code创建Python Function,处理Event Hub中的数据。当部署到Azure Function App后,函数无法执行,查看 Function 日志出现 Value cannot be null. (Parameter 'receiverConnectionString') 错误。

错误信息2023-01-04T09:12:06.725 [Error] Microsoft.Azure.WebJobs.Host: Error indexing method 'Functions.EventHubTrigger1'. Microsoft.Azure.WebJobs.EventHubs: Value cannot be null. (Parameter 'receiverConnectionString').

问题解答

这是因为在 function.json 文件中配置的 Event Connection String 方式错误。 不能直接使用Event Hub Namespace Connection String设置在 function.json 文件的 connection 值。  image

而是需要通过Function App 的 Application Setting 来设置。 

步骤一:在Function App门户中,添加名称为 receiverConnectionString 的配置参数,它的值就是Event Hub的Connection String。

配置结果如图: image

步骤二:把第一步中的receiverConnectionString 值,配置到function.json中的connection上。修改如下:

{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "type": "eventHubTrigger",
      "name": "events",
      "direction": "in",
      "eventHubName": "testmessage2",
      "connection": "receiverConnectionString",
      "cardinality": "many",
      "consumerGroup": "functiongroup"
    }
  ]
}

重新发布后, Value cannot be null. (Parameter 'receiverConnectionString')  错误就已经被解决了。

参考资料

适用于 Azure Functions 的 Azure 事件中心触发器https://docs.azure.cn/zh-cn/azure-functions/functions-bindings-event-hubs-trigger?tabs=in-process%2Cfunctionsv2%2Cextensionv5&pivots=programming-language-python#connection-string

当在复杂的环境中面临问题,格物之道需:浊而静之徐清,安以动之徐生。 云中,恰是如此!

分类: 【Azure 应用服务】

标签: Value cannot be null. (Parameter 'receiver...')receiverConnectionStringAzure Function PythonError indexing method 'Functions.EventHubTrigger1'