如何在负载平衡的服务器上处理Wesocket连接 [英] How to handle wesocket connections on load balanced servers

查看:80
本文介绍了如何在负载平衡的服务器上处理Wesocket连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的.net核心网络应用当前接受网络套接字连接,并在某些事件(编辑,删除,创建我们的某些实体)时将数据推送给客户端.

Our .net core web app currently accepts websocket connections and pushes out data to clients on certain events (edit, delete, create of some of our entities).

我们现在想对该应用程序进行负载平衡,但是预见到我们如何处理套接字连接方面的问题.基本上,如果我理解正确,那么只有处理特定事件的节点才会将数据推送到其客户端,而连接到其他节点的所有客户端都不会获得更新.

We would like to load balance this application now but foresee a problem in how we handle the socket connections. Basically, if I understand correctly, only the node that handles a specific event will push data out to its clients and none of the clients connected to the other nodes will get the update.

处理此问题的普遍接受的方法是什么?我能想到的最好的方法是也将同一事件发送到群集中的所有节点,以便它们也可以更新其客户端.这可能吗?我怎么知道集群中的其他节点?

What is a generally accepted way of handling this problem? The best way I can think of is to also send that same event to all nodes in a cluster so that they can also update their clients. Is this possible? How would I know about the other nodes in the cluster?

它将托管在AWS中.

推荐答案

您需要将事件分发到群集中的所有节点,以便它们每个都可以将更新推送到其websocket客户端.在AWS上执行此操作的一种常见方法是使用SNS将事件分发到所有节点.您也可以为此使用ElastiCache Redis发布/订阅.

You need to distribute the event to all nodes in the cluster, so that they can each push the update out to their websocket clients. A common way to do this on AWS is to use SNS to distribute the event to all nodes. You could also use ElastiCache Redis Pub/Sub for this.

这篇关于如何在负载平衡的服务器上处理Wesocket连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆