azure - SignalR核心: is ARR affinity needed when web sockets are enabled and the Azure app service is scaled out to multiple instances?

标签 azure asp.net-core websocket azure-web-app-service asp.net-core-signalr

我正在开发 asp.net core 2.2 MVC Web 应用程序。我们正在使用signal r core version 1.1.0 (通过 nuget 包 Microsoft.AspNetCore.SignalR 添加)。客户端应用程序是一个 angularjs 应用程序,引用版本 1.1.4 aspnet-signalr的JavaScript 库。

我们的应用程序部署在 Azure 上,托管应用程序服务水平扩展:目前有 two instances我们的网络应用程序已启动并运行。我正在使用 Google chrome version 75.0.3770.100 测试我的应用程序的行为在 Windows 10 计算机上。

应用服务已配置为启用 Web 套接字并禁用 ARR 关联性。我遇到了一种奇怪的行为,基本上,如果我测试我的应用程序并执行多次浏览器硬刷新(ctrl + F5),客户端应用程序无法连接到通知中心的情况会随机发生。 Google Chrome 控制台中报告以下错误:

WebSocket connection to 'wss://myapp.azurewebsites.net/notificationsHub?id=3Fmlw2yC5qm3vi0qny50Qg' failed: Error during WebSocket handshake: Unexpected response code: 404

Error: Failed to start the transport 'WebSockets': null

GET https://myapp.azurewebsites.net/notificationsHub?id=nEYPEDw5f0AkLz5otCAOyA 404

Error: Failed to start the transport 'ServerSentEvents': Error: Error occurred

GET https://myapp.azurewebsites.net/notificationsHub?id=2G9VVr5mcx7QT2wbSfwDLA&_=1561652513485 404

Error: Failed to start the transport 'LongPolling': Error

Error: Failed to start the connection: Error: Unable to initialize any of the available transports.

如果我更改应用服务配置,以便同时启用 Web 套接字和 ARR 关联性,一切都会顺利进行。我的怀疑是,当应用程序服务水平扩展时,无论传输协议(protocol)如何,都需要 ARR 关联(在我的例子中,服务器端应用程序和客户端浏览器都能够支持 Web 套接字协议(protocol))

根据我的理解,微软官方文档指出,使用 Web 套接字作为通信协议(protocol)时,不需要客户端 ARR 关联,即使托管应用服务水平扩展到多个实例。目前我不确定我对 signalr 核心文档的理解。

我错过了什么吗?我是否误解了官方文档?

2019 年 7 月 3 日编辑

对于这个主题(使用signal-r核心扩展Web应用程序)感兴趣的人,可以引用this github issue了解所有详细信息。

简单的回答是,新的 signal-r 核心实际上是有状态的,并且当应用程序扩展到多个服务器时需要粘性 session 。

如果您仅使用 Azure,则可以通过使用 Azure signalr service 避免使用粘性 session 并获得其他一些好处。 .

如果您不想使用此 Azure 服务,避免粘性 session 的唯一选择是配置 signal r 核心,以便避免客户端-服务器协议(protocol)协商,并且仅使用 Web 套接字完成通信(有关所有详细信息,请参阅链接的 github 问题)。请注意,这样做您将失去在不支持 Web 套接字时降级到其他协议(protocol)的能力,这是 signal-r 核心的核心功能之一。

最佳答案

如果您想禁用关联性,那么我认为您缺少的组件是托管的 SignalR 服务。这是代理服务 maintain当您的应用服务扩展时为您提供 session 信息。关注这些steps将 SignalR 服务作为服务依赖项添加到您的项目中。

关于azure - SignalR核心: is ARR affinity needed when web sockets are enabled and the Azure app service is scaled out to multiple instances?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56795602/

相关文章:

.net - 为什么 Azure 应用服务找不到我的 GoDaddy 证书?

azure - Python Azure函数: Runtime is unreachable 503 error

entity-framework - Azure 部署连接字符串

visual-studio-2015 - 在 VS Code 上运行 asp.net core 时,Configuration.GetConnectionString 返回 null,但在 Visual Studio 上运行正常

javascript - 如何在部分 View 中保留 ajax 之后的选择值?

azure - Vagrant-Azure : Guest machine can't connect to host machine (Unable to copy SMB files)

cookies - .net core 是否可以支持多个 cookie 域?

mysql - AngularJs 实时应用程序与 mysql 服务器

multithreading - ServerEndpoint 的每个方法是否由不同的线程执行?

java - 使用 WebSocket 进行服务器与服务器通信