【发布时间】:2021-09-06 02:11:01
【问题描述】:
我在使用 SignalR、ASP.Net Core 3.1、Kestrel 和 Angular 10 创建的应用程序时遇到了一些问题。希望有人能够帮助我。我在论坛里搜索了很长时间,但无法解决当前的错误。
该应用程序是仪表板类型 - 可以单击几个组件来过滤实时数据。一些基本的 UI 组件将始终显示,并且应始终从集线器获取数据流。
启动设置:
services.AddSignalR(hubOptions =>
{
hubOptions.EnableDetailedErrors = true;
// Maybe I don’t need those, but connection is dropping very frequently with defaults.
hubOptions.KeepAliveInterval = TimeSpan.FromMinutes(1);
hubOptions.ClientTimeoutInterval = TimeSpan.FromSeconds(5);
hubOptions.ClientTimeoutInterval = TimeSpan.FromSeconds(15);
})
.AddNewtonsoftJsonProtocol();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapHub<MyHub>("/data");
});
服务器设置:
webBuilder.ConfigureKestrel(serverOptions =>
{
serverOptions.Listen(IPAddress.Any, 80, listenOptions =>
{
listenOptions.UseConnectionLogging();
});
serverOptions.Limits.KeepAliveTimeout = TimeSpan.FromDays(30);
serverOptions.Limits.MinRequestBodyDataRate = null;
serverOptions.Limits.MinResponseDataRate = null;
});
连接设置:
private buildHubConnection(uri: string): signalR.HubConnection {
return new signalR.HubConnectionBuilder()
.withUrl(uri)
.configureLogging(signalR.LogLevel.Debug)
.withAutomaticReconnect({nextRetryDelayInMilliseconds: () => 2000})
.build();
}
与:
serverTimeoutInMilliseconds = 100000;
问题如下:
响应速度很慢,直到崩溃。服务器通过流向仪表板上的每个组件推送数据,但它甚至会发生请求超时(我使用长轮询测试了该部分,但 Web 套接字也存在相同的延迟)。
我希望来自服务器的数据会在某个正常时间被推回,这可以通过 UI 上的转换来覆盖。延迟太大,到了请求超时。
使用 Web Sockets,这是错误消息:
Error: Connection disconnected with error 'Error: Server timeout elapsed without receiving a message from the server.'.
即使重新连接成功,数据也不存在。
在大多数情况下,场景是重新连接尝试的长循环,并出现以下错误:
Information: Connection reconnecting because of error 'Error: Server timeout elapsed without receiving a message from the server.'.
即使控制台日志成功重新连接后,dataQuery 也会失败:
Error: Cannot send data if the connection is not in the 'Connected' State.
这一切对我来说是不合逻辑的。如果服务器应该流式传输数据,为什么会关闭连接?你能帮我弄清楚可能缺少什么,或者可能是什么问题吗?感谢任何人的回复。
【问题讨论】:
标签: angular signalr asp.net-core-signalr kestrel