启用会话的函数应用程序的 Azure 服务总线触发器 - Node.js

Azure Service bus trigger for function app with session enabled - Node.js

我有一个由启用会话的服务总线触发的功能,但我收到错误:

Microsoft.Azure.ServiceBus: It is not possible for an entity that requires sessions to create a non-sessionful message receiver

有没有办法启用 nodejs 应用程序的会话?

我试图编辑我的 host.json 但它没有用,SessionHandlerOptions 没有显示为 serviceBus 的 属性... "Property SessionHandlerOptions is not allowed"

{
  "version": "2.0",
  "extensions": {
    "serviceBus": {
      "SessionHandlerOptions": ....

      }
    }
  }
}

也尝试在 function.json 中添加 "isSessionsEnabled": true 但仍然出现相同的错误。

有什么想法吗?

这是一个常见问题。自 Azure Functions 创建以来,Azure Functions 不支持服务总线会话。这种情况会持续3-4年。几个月前出现了一个 nuget 包来支持这个。对于 node.js,我找不到要安装的 SDK。如果你使用 C#,现在它有一个解决方案。但是对于 node.js,我不确定。你可以试试最新的SDK,说不定能支持这个。

这是一个函数SDK issue。你可以看看。

所以,几个小时后,感谢@BowmanZhu 的建议,我找到了在使用 node.js 时也有效的解决方案。 我正在使用 azure-functions-core-tools,因此请将其更新到最新版本:

npm install -g azure-functions-core-tools@2

从项目的根目录安装 ServiceBus 扩展包 3.1.1:

dotnet add package Microsoft.Azure.WebJobs.Extensions.ServiceBus --version 3.1.1 

extensions.csproj 文件中,您现在应该看到该包的包引用是 3.1.1

<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.ServiceBus" Version="3.1.1" />

然后 运行:

func extensions install 

最后添加 function.json 添加绑定:

"isSessionsEnabled": true

运行 func start 在本地启动函数应用程序。您应该不会再看到错误消息,启用会话的队列可用于触发该函数。