我正在使用AKKA框架及其Java API来创建一个actor系统。这是演员的要点。 actor负责处理图中的节点。对于图中同一级别的节点,处理可以并行完成,因此我需要在达到这样的级别时并行地生成actor
SupervisorActor extends Actor {
// if (msg instanceOf something)
// spawn child actor for every level in a graph
childActor.tell(node, getself());
How do I send messages to two childActors here when I have two nodes at the same level?
}
答案 0 :(得分:0)
Actors以异步方式进行通信,因此您可以创建2个actor并调用tell两次向每个actor发送一条消息,它们将同时处理它。
如果您满足以下条件:
ActorRef child1 = getContext().actorOf(Props.create(MyActor.class), "child1");
ActorRef child2 = getContext().actorOf(Props.create(MyActor.class), "child2");
child1.tell(msg1, getself());
child2.tell(msg2, getself());
将同时创建actor child1和child2并同时处理消息。
答案 1 :(得分:0)
假设您要求创建同一个actor的多个实例。
您可以在配置文件中定义您想要的演员实例数。
akka {
/my-service {
router = round-robin-pool // strategy how message will be served
nr-of-instances = 3} // here you can define the number of instance
}