【Azure 应用服务】Azure Function Python函数部署到Azure后遇见 Value cannot be null. (Parameter 'receiverConnectionString') 错误
问题描述
使用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 值。
而是需要通过Function App 的 Application Setting 来设置。
步骤一:在Function App门户中,添加名称为 receiverConnectionString 的配置参数,它的值就是Event Hub的Connection String。
配置结果如图:
步骤二:把第一步中的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
当在复杂的环境中面临问题,格物之道需:浊而静之徐清,安以动之徐生。 云中,恰是如此!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?