Azure SignalR 服务常见问题解答Azure SignalR Service FAQ

Azure SignalR 服务是否随时可用于生产?Is Azure SignalR Service ready for production use?

是的,对 ASP.NET Core SignalRASP.NET SignalR 的支持都已正式发布。Yes, both the support for ASP.NET Core SignalR and ASP.NET SignalR is all generally available.

如果存在多个应用程序服务器,客户端消息是发送到所有服务器,还是只发送到其中的一个服务器?When there are multiple application servers, are client messages sent to all servers or just one of them?

客户端与应用程序服务器之间存在一对一映射。There's a one-to-one mapping between a client and an application server. 来自一个客户端的消息始终会发送到同一个应用程序服务器。Messages from one client are always sent to the same application server.

在客户端或应用程序服务器断开连接之前,将保持映射。The mapping is maintained until the client or application server disconnects.

如果我的某个应用程序服务器已关闭,如何发现这种情况并收到通知?If one of my application servers is down, how can I find it and get notified?

Azure SignalR 服务将监视应用程序服务器的检测信号。Azure SignalR Service monitors heartbeats from application servers. 如果在指定的一段时间内未收到检测信号,则认为应用程序服务器处于脱机状态。If heartbeats are not received for a specified period of time, the application server is considered offline. 映射到此应用程序服务器的所有客户端连接将会断开。All client connections mapped to this application server will be disconnected.

从 ASP.NET Core SignalR SDK 切换到 Azure SignalR 服务 SDK 时,自定义 IUserIdProvider 为何引发异常?Why does my custom IUserIdProvider throw an exception when I'm switching from ASP.NET Core SignalR SDK to Azure SignalR Service SDK?

调用 IUserIdProvider 时,ASP.NET Core SignalR SDK 与 Azure SignalR 服务 SDK 的参数 HubConnectionContext context 不相同。The parameter HubConnectionContext context is different between the ASP.NET Core SignalR SDK and the Azure SignalR Service SDK when IUserIdProvider is called.

在 ASP.NET Core SignalR 中,HubConnectionContext context 是包含所有属性有效值的物理客户端连接的上下文。In ASP.NET Core SignalR, HubConnectionContext context is the context from the physical client connection with valid values for all properties.

在 Azure SignalR 服务 SDK 中,HubConnectionContext context 是逻辑客户端连接的上下文。In the Azure SignalR Service SDK, HubConnectionContext context is the context from the logical client connection. 物理客户端将连接到 Azure SignalR 服务实例,因此,只提供有限数量的属性。The physical client is connected to the Azure SignalR Service instance, so only a limited number of properties are provided.

目前只能访问 HubConnectionContext.GetHttpContext()HubConnectionContext.UserFor now, only HubConnectionContext.GetHttpContext() and HubConnectionContext.User are available for access. 你可以查看源代码You can check the source code.

是否可以使用 ASP.NET Core SignalR 配置在服务器端的 Azure SignalR 服务中可用的传输?Can I configure the transports available in Azure SignalR Service on the server side with ASP.NET Core SignalR? 例如,是否可以禁用 WebSocket 传输?For example, can I disable WebSocket transport?

不是。No.

默认情况下,Azure SignalR 服务提供 ASP.NET Core SignalR 所支持的所有三种传输。Azure SignalR Service provides all three transports that ASP.NET Core SignalR supports by default. 无法对其进行配置。It's not configurable. Azure SignalR 服务将处理连接以及所有客户端连接的传输。Azure SignalR Service will handle connections and transports for all client connections.

可以按照 ASP.NET Core SignalR 配置中所述配置客户端传输。You can configure client-side transports as documented in ASP.NET Core SignalR configuration.

Azure 门户中显示的指标(例如消息计数或连接计数)的含义是什么?What is the meaning of metrics like message count or connection count shown in the Azure portal? 我应该选择哪种聚合类型?Which kind of aggregation type should I choose?

可以在 Azure SignalR 服务中的消息和连接中找到有关计算这些指标的详细信息。You can find details about we calculate these metrics in Messages and connections in Azure SignalR Service.

在 Azure SignalR 服务资源的概述窗格上,我们已经为你选择了合适的聚合类型。On the overview pane of Azure SignalR Service resources, we've already chosen the appropriate aggregation type for you. 如果转到指标窗格,你可以将该聚合类型作为引用应用到 Azure SignalR 服务中的消息和连接If you go to the metrics pane, you can take the aggregation type to Messages and connections in Azure SignalR Service as a reference.

DefaultServerlessClassic 服务模式的含义是什么?What is the meaning of the Default, Serverless, and Classic service modes? 如何选择?How can I choose?

对于新应用程序,应只使用默认和无服务器模式。For new applications, only default and serverless mode should be used. 主要区别在于你是否拥有与服务建立服务器连接的应用程序服务器(例如,使用 AddAzureSignalR() 连接到服务)。The main difference is whether you have application servers that establish server connections to the service (i.e. use AddAzureSignalR() to connect to service). 如果是,则使用默认模式,否则使用无服务器模式。If yes use default mode, otherwise use serverless mode.

经典模式旨在实现现有应用程序的后向兼容性,因此不应将其用于新应用程序。Classic mode is designed for backward compatibility for existing applications so should not be used for new applications.

有关服务模式的详细信息,请参阅这篇文档For more information about service mode in this doc.

能否在无服务器模式下从客户端发送消息?Can I send message from client in serverless mode?

如果在 SignalR 实例中配置 Upstream,则可以从客户端发送消息。You can send message from client if you configure upstream in your SignalR instance. Upstream 是一组终结点,可接收来自 SignalR 服务的消息和连接事件。Upstream is a set of endpoints that can receive messages and connection events from SignalR service. 如果未配置 Upstream,则将忽略来自客户端的消息。If no upstream is configured, messages from client will be ignored.

有关 Upstream 的详细信息,请参阅这篇文档For more information about upstream see this doc.

Upstream 目前以公共预览版提供。Upstream is currently in public preview.

将 Azure SignalR 服务与 ASP.NET SignalR 结合使用时是否有功能差异?Are there any feature differences in using Azure SignalR Service with ASP.NET SignalR?

使用 Azure SignalR 服务时,ASP.NET SignalR 的某些 API 和功能不受支持:When you're using Azure SignalR Service, some APIs and features of ASP.NET SignalR aren't supported:

  • 不支持在客户端和中心之间传递任意状态的功能(通常称为 HubState)。The ability to pass arbitrary state between clients and the hub (often called HubState) is not supported.
  • 不支持 PersistentConnection 类。The PersistentConnection class is not supported.
  • 不支持永久帧传输。Forever Frame transport is not supported.
  • Azure SignalR 服务不再重播客户端脱机时发送给客户端的消息。Azure SignalR Service no longer replays messages sent to the client when the client is offline.
  • 使用 Azure SignalR 服务时,在连接期间内,一个客户端连接的流量始终路由(也称为“粘滞”)到一个应用服务器实例。When you're using Azure SignalR Service, the traffic for one client connection is always routed (also called sticky) to one app server instance for the duration of the connection.

对 ASP.NET SignalR 的支持侧重于兼容性,因此并非 ASP.NET Core SignalR 的所有新功能都受到支持。Support for ASP.NET SignalR is focused on compatibility, so not all new features from ASP.NET Core SignalR are supported. 例如,MessagePack 和流式处理仅适用于 ASP.NET Core SignalR 应用程序 。For example, MessagePack and Streaming are available only for ASP.NET Core SignalR applications.

你可以为不同的服务模式(ClassicDefaultServerless)配置 Azure SignalR 服务。You can configure Azure SignalR Service for different service modes: Classic, Default, and Serverless. ASP.NET 不支持 Serverless 模式。The Serverless mode is not supported for ASP.NET. 也不支持数据平面 REST API。The data-plane REST API is also not supported.

我的数据存放在什么位置?Where does my data reside?

Azure SignalR 服务作为数据处理器服务工作。Azure SignalR Service works as a data processor service. 它不会存储任何客户内容,且设计包含数据驻留。It won't store any customer content, and data residency is included by design. 如果将 Azure SignalR 服务与其他 Azure 服务(例如 Azure 存储)结合用于诊断,请参阅此白皮书,以获取有关如何将数据驻留在 Azure 区域中的指南。If you use Azure SignalR Service together with other Azure services, like Azure Storage for diagnostics, see this white paper for guidance about how to keep data residency in Azure regions.