我们正在使用AWS kubernetes集群(EKS),带有ALB/入口和redis-cache用于信号连接。如果我们的副本集为3,则连接到服务时会随机抛出404错误。
SkipNegotiation = true
Transports = Microsoft.AspNetCore.Http.Connections.HttpTransportType.WebSockets
一切似乎都正常。我找不到将SkipNegotation
设置为true的任何缺点。但找不到这是否有任何副作用(默认设置为false
肯定有原因)。
将SkipNegotation
设置为true
是否会导致其他问题?
正在运行的示例代码:
Console.WriteLine("Start");
HubConnection connection = new HubConnectionBuilder()
.WithUrl("https://<url>/api/v1/taskboard", o =>
{
o.Transports = Microsoft.AspNetCore.Http.Connections.HttpTransportType.WebSockets;
o.SkipNegotiation = true;
})
.WithAutomaticReconnect()
.Build();
await connection.StartAsync();
connection.On<string>("ReceiveMessage", message =>
{
Console.WriteLine(message);
});
for (int i = 0; i < 20; i++)
{
await connection.InvokeAsync("SendMessage", $"Hello {i}");
await Task.Delay(55);
}
await connection.StopAsync();
await connection.DisposeAsync();
- 编辑**
这些设置已添加到入口:
alb.ingress.kubernetes.io/certificate-arn: arn:aws:acm:......
alb.ingress.kubernetes.io/listen-ports: '[{"HTTP": 80}, {"HTTPS":443}]'
alb.ingress.kubernetes.io/ssl-redirect: '443'
alb.ingress.kubernetes.io/scheme: internet-facing
alb.ingress.kubernetes.io/subnets: subnet-..., subnet-...
alb.ingress.kubernetes.io/load-balancer-attributes: idle_timeout.timeout_seconds=600
alb.ingress.kubernetes.io/target-group-attributes: stickiness.enabled=true,stickiness.lb_cookie.duration_seconds=600
alb.ingress.kubernetes.io/healthcheck-path: /HealthCheck
alb.ingress.kubernetes.io/healthcheck-port: '80'
1条答案
按热度按时间vcirk6k61#
使用SkipNegotiation的主要原因是为了避免使用粘性会话,当您想与SignalR服务器建立连接时,客户端会向服务器发送一个post请求,直到客户端收到服务器的响应后,连接才会建立:
客户请求:
服务器响应:
为了避免使用粘性会话,客户端需要跳过协商,但被限制为仅使用websocket。
来源:https://github.com/aspnet/SignalR/blob/release/2.2/specs/TransportProtocols.md