You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure门户中Node.js v4 Service Bus触发器失效,本地运行正常

解决Azure Functions Node.js v4模型Service Bus触发器绑定未注册问题

问题场景

使用Azure Functions Node.js v4编程模型创建Service Bus队列触发函数,本地通过func start运行正常,但部署到Azure后无法处理消息,Insights中报错:

The 'MyFunctionName' function is in error: The binding type(s) 'serviceBusTrigger' are not registered. Please ensure the type is correct and the binding extension is installed.

已验证以下配置无误:

  • Azure应用设置中连接字符串配置正确(不含EntityPath)
  • 本地与Azure运行时均为v4,Node.js版本18
  • Function App处于运行状态
  • 队列名称和连接字符串与函数定义一致

函数配置代码:

app.serviceBusQueue('MyFunctionName', {
  queueName: 'myQueueName',
  connection: 'ServiceBusConnectionString',
  handler: azureFunction,
  isSessionsEnabled: true,
});

host.json配置:

{
  "version": "2.0",
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[4.0.0, 5.0.0)"
  },
  "functionTimeout": "00:04:00",
  "extensions": {
    "serviceBus": {
      "prefetchCount": 10,
      "messageHandlerOptions": {
        "maxConcurrentCalls": 16,
        "autoComplete": true,
        "maxAutoRenewDuration": "00:05:00"
      }
    }
  }
}

解决步骤

1. 确认项目依赖版本

确保package.json中@azure/functions包版本为4.x,与扩展包兼容:

{
  "dependencies": {
    "@azure/functions": "^4.0.0"
  }
}

执行以下命令重新安装依赖并部署:

npm install
func azure functionapp publish <你的Function App名称>

2. 验证Function App核心设置

在Azure门户的Function App应用设置中检查:

  • FUNCTIONS_EXTENSION_VERSION 设为 ~4
  • NODE_VERSION 设为 18.x
  • FUNCTIONS_WORKER_RUNTIME 设为 node

3. 确保host.json同步部署

确认Azure上的host.json与本地完全一致,若部署时未自动同步,可手动上传该文件或重新部署整个项目。

4. 重启Function App

在Azure门户的Function App概览页点击重启,清除扩展加载缓存,触发Service Bus绑定扩展重新注册。

5. 排查部署模式问题

若使用Zip部署,确保打包文件包含所有必要文件(host.json、package.json、函数代码等);优先使用Azure Functions Core Tools的func publish命令部署,该命令会自动处理扩展依赖的加载。

6. 锁定扩展包具体版本

若扩展包范围版本存在兼容性问题,可将host.json中的extensionBundle.version锁定到具体兼容版本,例如:

"extensionBundle": {
  "id": "Microsoft.Azure.Functions.ExtensionBundle",
  "version": "[4.15.0, 5.0.0)"
}

修改后重新部署。

内容的提问来源于stack exchange,提问作者Davide Bracaglia

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.17 11:23:14