创建 SignalR 服务器以跨多个应用程序使用

Create SignalR server to use across multiple applications

我正在构建一个面向微服务的 .NET Core Web 应用程序,现在我想添加实时通信。可以创建 SignalR 服务器并将其发布到 Azure 上吗?我想在我的微服务中使用它在某个事件发生时向用户发送消息。

可以,这是官方快速入门示例。 https://docs.microsoft.com/en-us/azure/azure-signalr/signalr-quickstart-dotnet-core

是的,你可以将你的应用程序部署到 Azure 并将你的用户指向你的中心终结点,没有任何问题。您在这里有两个选择:

  • 如果您要扩展应用程序,请使用 SignalR 并手动管理连接和其他 signalR 内容。例如,当您有 2 个 Web 应用程序并且客户端连接到其中一个时,您需要“告诉”其他应用程序您有一个新的客户端连接使用例如 Redis Blackplane。
  • 使用Azure SignalR不需要这种管理,你只需要提供1个带有hub逻辑的app即可。因此,当客户端连接到您的集线器时,它会自动重定向到 Azure SignalR.

您可以在此处阅读有关这两个选项的更多信息: https://docs.microsoft.com/pt-pt/azure/azure-signalr/signalr-concept-scale-aspnet-core

Why not deploy SignalR myself?´

It is still a valid approach to deploy your own Azure web app supporting ASP.NET Core SignalR as a backend component to your overall web application. One of the key reasons to use the Azure SignalR Service is simplicity. With Azure SignalR Service, you don't need to handle problems like performance, scalability, availability. These issues are handled for you with a 99.9% service-level agreement. Also, WebSockets are typically the preferred technique to support real-time content updates. However, load balancing a large number of persistent WebSocket connections becomes a complicated problem to solve as you scale. Common solutions leverage: DNS load balancing, hardware load balancers, and software load balancing. Azure SignalR Service handles this problem for you. Another reason may be you have no requirements to actually host a web application at all. The logic of your web application may leverage Serverless computing. For example, maybe your code is only hosted and executed on demand with Azure Functions triggers. This scenario can be tricky because your code only runs on-demand and doesn't maintain long connections with clients. Azure SignalR Service can handle this situation since the service already manages connections for you. See the overview on how to use SignalR Service with Azure Functions for more details.