在 Actors 内部或外部 Akka.NET 中将代理的 websocket 客户端放在哪里?

Where to put websocket clients for a proxy in Akka.NET inside or outside Actors?

我是 Akka.NET 的新手。我正在构建某种 websockets 代理,我想使用 Akka.NET 通过其 actor 系统处理(转换和转发)传入流量。但我想知道最好的方法是什么。

我的问题是:

@frankhommers 所以我一直在开发一个应用程序,该应用程序使用 WebSocket 消耗实时提要并将解析的消息传递到 Akka.NET 集群。

我为此采取的方法可以概括为:

  1. 将 WebSocket 使用者实现为 Akka.Streams Source. Akka.Streams provides a highly composable and performant API for doing things like deserializing, filtering, and transforming messages coming off of the websocket and it's able to handle downstream backpressure via buffering too. You can find some examples of third-party implementations of Akka.Streams Sources for things like Azure Service Bus et al here: https://github.com/AkkaNetContrib/Alpakka - 这应该有助于您了解如何自己实现。
  2. 我将我的 Source<string> 作为 ClusterSingleton 启动,这保证在任何给定时间集群中只有一个 WebSocket 消费者副本。这个源最终会将其结果广播给集群中其他地方的几个参与者,他们将处理反序列化的消息并用它做其他事情。

如果您还没有接触 Akka.NET 集群,请不要着急 - 您可以在更加熟悉 Akka.NET 之后再引入该功能。但该设计的目标是通过只有一个提要消费者并让它通过 Akka.NET 自己的消息传递功能简单地将其结果广播到其他地方来提供相当高的一致性。