使用 ASP.NET Web 应用程序作为 SignalR 客户端

Using ASP.NET Web application as SignalR client

我的团队正在决定后端系统的架构:

  1. Webserver A is an ASP.NET MVC application with ASP.NET Web API component, hosted in Azure Website.
  2. Windows Service B is a self-hosted OWIN server that will periodically push notifications to clients who subscribes to the notification, hosted in Azure VM.
  3. Windows Service C is a client that subscribes to notification from B, hosted in Azure VM.

由于我们或多或少地处于 .NET 堆栈中,我们将 B 实现为 SignalR 服务器,而 C 是 SignalR 客户端。这部分似乎工作得很好。

现在我们也希望 A 订阅 B,但我意识到这意味着 ASP.NET Web 服务器将充当 SignalR 客户端,而不是典型的场景它充当 SignalR 服务器。

我想我们可以在 Global.asax 中初始化 SignalR 连接,并使进程永远 运行 避免 AppDomain 回收。但是,当让 Web 服务器执行服务 Web 请求以外的其他操作时,我觉得有点不确定。此解决方案还使 Web 服务器不是无状态的,因为它需要保持 Web 套接字连接处于活动状态。

使 ASP.NET 应用程序成为 SignalR 客户端是否存在根本性错误?这个设置有什么可能的问题吗?

在 Azure 中,您无法确定您的 AppDomain 不会回收。由于多种原因,它可以自行重启以恢复正常,然后您将最终与 SingleR 服务器建立新连接。你觉得合适吗?

此外,SingleR 主要用于改进 Web 功能,使 Web 客户端上的轮询和刷新变得简单。但是由于您的要求似乎都是后端的东西,我建议您使用任何其他事件驱动模式。检查 Azure 服务总线 topic/subscription 模型,让不同的组件侦听各种事件并相应地采取行动。