识别 Akka Actor 的多个实例

Identifying multiple instances of Akka Actors

正在学习Akka Actor编程(Java),正在reading/watching几个教程。我想我掌握了大部分。

但是有一件事让我感到困惑,如果这是一个菜鸟问题,我很抱歉,但它是关于拥有多个 Actors 实例,以及如何 create/retrieve/identify 它们?

假设我有一个 Account Actor,并且想要它的多个实例。我是否应该保留 "account numbers" 的记录和对适当 Actor 实例的引用?喜欢一个

Map<String,ActorRef> 

之类的东西,存储在 Supervisor/Parent Actor?

在启动时,我应该为每个帐户创建一个 Actor,还是应该有一个工厂在第一次需要时创建帐户 Actor?那么坚持呢?假设账户想要加载已应用的交易列表?

我应该手动编写所有这些代码,还是有更聪明的 "best practice" 这里我不明白?

在您的情况下,如果他们不在主管的当前上下文中,您可以简单地创建 persistent actors under the supervisor where persistence id would correspond to the account number. Therefore, account number can be used as a unique identifier. To obtain actors from context of supervisor, you can use ActorContext#child method or simply to recover them from persistent store by using ActorContext#actorOf