Blazor在负载均衡时如何传递对象到不同服务器。

huangapple go评论48阅读模式
英文:

How does Blazor carry objects across servers when load balancing

问题

I have some Blazor server side code that I can reduce down to this little bit:

@foreach (var employee in Employees)
{
    <tr>
        <td class="btn-group-sm">
            <button class="btn btn-outline-danger"
                @onclick="() => HandleDelete(employee)">
                Delete
            </button>
        </td>
    </tr>
}

And that calls HandleDelete(employee) on a click, passing the employee object that it has persisted in the session data (I assume) to pass when the click occurs.

However, if I have multiple servers being load balanced, what happens if the submit event is sent to a different server? That different server won't have the employee object (I believe).

Does this all depend on the HTTPS session staying connected to the original server, and all subsequent communication going to that server?

And if so, in a fail-over situation, what happens? In that case, it's definitely a connection to a new server getting that submit action.

英文:

I have some Blazor server side code that I can reduce down to this little bit:

@foreach (var employee in Employees)
{
    &lt;tr&gt;
        &lt;td class=&quot;btn-group-sm&quot;&gt;
            &lt;button class=&quot;btn btn-outline-danger&quot;
               @onclick=&quot;() =&gt; HandleDelete(employee)&quot;&gt;
               Delete
            &lt;/button&gt;
        &lt;/td&gt;
    &lt;/tr&gt;
}

And that calls HandleDelete(employee) on a click passing the employee object that it has persisted in the session data (I assume) to pass when the click occurs.

However, if I have multiple servers being load balanced, what happens if the submit event is sent to a different server? That different server won't have the employee object (I believe).

Does this all depend on the https session staying connected to the original server and all subsequent communication going to that server?

And if so, in a fail-over situation, what happens. In that case it's definitely a connection to a new server getting that submit action.

答案1

得分: 0

Blazor Server不支持完全的负载均衡。客户端应始终与同一服务器上相同的Blazor电路保持连接。

这可以通过在负载均衡器上使用粘性会话、使用Azure SignalR服务或使用SkipNegotiation设置来实现。

使用SkipNegotiation设置时,负载均衡器应将所有SignalR消息广播到所有节点。

https://learn.microsoft.com/en-us/aspnet/core/signalr/scale

英文:

Blazor Server does not support full load balancing. The client should always stay connected with the same Blazor circuit on the same server.

This can be accomplished by using sticky sessions on the load balancer, by using the Azure SignalR service or by using the SkipNegotiation setting.

When using the SkipNegotiation setting, the load balancer should broadcast all SignalR messages to all nodes.

https://learn.microsoft.com/en-us/aspnet/core/signalr/scale

huangapple
  • 本文由 发表于 2023年2月14日 02:22:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/75439824.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定