【Azure 应用服务】Azure Function Python函数部署到Azure后遇见 Value cannot be null. (Parameter 'receiverConnecti...

问题描述

使用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...'), receiverConnectionString, Azure Function Python, Error indexing method 'Functions.EventHubTrigger1'

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容