azure - SignalRCore 和 Azure 函数
问题描述
我有一个 Asp.Net-Core 3.0 Web 服务,我将其作为单一容器功能应用程序运行。这对我的 Rest api 非常有用。
但是我最近添加了一个 SignalR 集线器来添加通知服务,但这在 Azure 函数中我的 Web 应用程序的托管版本中不起作用。当我尝试使用 .Net SignalRCore 3 客户端连接到集线器时,出现以下错误:
服务器在握手开始之前断开了连接。
当我将容器作为基本 Azure 容器实例运行时,SignalR 功能运行良好。
有什么想法为什么会发生这种情况,甚至可以将 SignalR 集线器添加到托管的 azure 函数 docker 容器中吗?
解决方案
似乎 SignalR 在设计上托管在函数应用程序中的 Asp.Net-Core3 Docker 容器实例中不起作用,因为函数应用程序应该是无状态的,而 SignalR 不是。为此,您需要使用 AspNetCore Web 服务中的单独 Azure SignalR 服务。
https://azure.microsoft.com/en-us/services/signalr-service/
StartUp
并更改您班级的注册码。
var signalRServerBuilder = services.AddSignalR();
var signalRConnectionString = m_configuration[@"SignalRConnectionString"];
if (!string.IsNullOrWhiteSpace(signalRConnectionString))
{
signalRServerBuilder.AddAzureSignalR(signalRConnectionString);
}
推荐阅读
- chart.js - Chartjs 带范围的折线图
- java - PKIX 路径构建失败:我无法修复它请为我们提供一些解决方案
- openssl - 带有 EVP API 的 RSA
- c# - 使用checkedlistbox从Datagridview中选择数据
- ios - 在 iPhone X 和更早版本中无法返回到以前的视图控制器
- vue.js - node-red 中的自定义 UI(node-red-contrib-uibuilder & VueJS & 导入包)
- java - Jsoup 选择器:h2 之后的第二个 div
- elasticsearch - 在同一集群环境中使用 dockerfile 使用 Kibana 创建 3 个 Elasticsearch 集群和 1 个 Balancer 节点
- datepicker - 如何将引导日期选择器添加到制表符标题过滤器
- javascript - 查询?在正则表达式中 - JAVASCRIPT