SignalRCore 和 Azure 函数
SignalRCore and Azure functions
我得到了一个 Asp.Net-Core 3.0 网络服务,我 运行 作为单一容器功能应用程序。这对我的休息非常有用 api。
但我最近添加了一个 SignalR 中心来添加通知服务,但这在我的 Azure 函数中的 Web 应用程序的托管版本中不起作用。当我尝试使用 .Net SignalRCore 3 客户端连接到集线器时,出现以下错误:
The server disconnected before the handshake could be started.
当我 运行 将容器作为基本 Azure 容器实例时,SignalR 功能运行良好。
知道为什么会发生这种情况,是否可以将 SignalR 集线器添加到托管 docker 容器的 azure 函数中?
似乎 SignalR 在 Asp.Net-Core3 Docker 设计上托管在函数应用程序中的容器实例中不起作用,因为函数应用程序应该是无状态的,而 SignalR 不是。为此,您需要使用来自 AspNetCore 网络服务的单独 Azure SignalR 服务。
https://azure.microsoft.com/en-us/services/signalr-service/
并更改您StartUp
class中的注册码。
var signalRServerBuilder = services.AddSignalR();
var signalRConnectionString = m_configuration[@"SignalRConnectionString"];
if (!string.IsNullOrWhiteSpace(signalRConnectionString))
{
signalRServerBuilder.AddAzureSignalR(signalRConnectionString);
}
我得到了一个 Asp.Net-Core 3.0 网络服务,我 运行 作为单一容器功能应用程序。这对我的休息非常有用 api。
但我最近添加了一个 SignalR 中心来添加通知服务,但这在我的 Azure 函数中的 Web 应用程序的托管版本中不起作用。当我尝试使用 .Net SignalRCore 3 客户端连接到集线器时,出现以下错误:
The server disconnected before the handshake could be started.
当我 运行 将容器作为基本 Azure 容器实例时,SignalR 功能运行良好。
知道为什么会发生这种情况,是否可以将 SignalR 集线器添加到托管 docker 容器的 azure 函数中?
似乎 SignalR 在 Asp.Net-Core3 Docker 设计上托管在函数应用程序中的容器实例中不起作用,因为函数应用程序应该是无状态的,而 SignalR 不是。为此,您需要使用来自 AspNetCore 网络服务的单独 Azure SignalR 服务。
https://azure.microsoft.com/en-us/services/signalr-service/
并更改您StartUp
class中的注册码。
var signalRServerBuilder = services.AddSignalR();
var signalRConnectionString = m_configuration[@"SignalRConnectionString"];
if (!string.IsNullOrWhiteSpace(signalRConnectionString))
{
signalRServerBuilder.AddAzureSignalR(signalRConnectionString);
}