从存储帐户部署代码时,Azure Functions 事件中心触发绑定注册失败

Azure functions event hub trigger binding registration failing when deploying code from storage account

使用应用设置 WEBSITE_RUN_FROM_PACKAGE 从存储帐户中的压缩代码部署代码时,事件中心触发器绑定注册失败。出现以下错误:

The binding type(s) eventHubTrigger are not registered

相同的代码在通过 VS code 解压缩部署时工作正常。

Host.json

{
  "version": "2.0",
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[2.*, 3.0.0)"
}

Function.json

{
  "bindings": [
    {
      "type": "eventHubTrigger",
      "name": "myEventHubMessage",
      "direction": "in",
      "eventHubName": "eventHubName",
      "connection": "myEventHubReadConnectionAppSetting"
    }
  ]
}

更新 host.json 并添加“扩展”

{
"version": "2.0",

"extensions": {
    "blobs": {},
    "cosmosDb": {},
    "durableTask": {},
    "eventHubs": {},
    "http": {},
    "queues": {},
    "sendGrid": {},
    "serviceBus": {}
},

"extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[2.*, 3.0.0)"
}}
  • 使用上面的提示在 host.json
  • 中明确提及扩展
  • 将 host.json 移动到代码文件夹上方的一层,我将其保持在同一层。

PS:这与使用 Azure 函数扩展的 VS 代码部署一起工作 - 当在根级别未检测到 host.json 时,VS 代码会根据指定的触发器自动安装扩展在 functions.json