简体   繁体   English

如何从Akka中的非演员获取对现有演员的引用?

[英]How to get a reference to an existing actor from a non-actor in Akka?

In my application, I have a class which needs to communicate with an existing actor already created in an actorSystem. 在我的应用程序中,我有一个类需要与已经在actorSystem中创建的现有actor通信。 How do I get a reference to that actor from this non-actor class? 如何从非演员类中获得对该演员的引用?

If you have the reference to the actor system ( https://doc.akka.io/api/akka/current/akka/actor/ActorSystem.html ), then you can simply invoke actorSelection with the path of the actor. 如果您具有对actor系统的引用( https://doc.akka.io/api/akka/current/akka/actor/ActorSystem.html ),则只需使用actorSelection的路径调用actorSelection即可。 This will give you an ActorSelection , on which you can call resolveOne , and then wait until you get the reference of the actor. 这将为您提供ActorSelection ,您可以在其上调用resolveOne ,然后等到获得该actor的引用。 Once you have the actor reference, you can send messages to it. 一旦有了演员参考,就可以向它发送消息。

Here is more information about addressing actors: https://doc.akka.io/docs/akka/current/general/addressing.html . 以下是有关与演员打交道的更多信息: https : //doc.akka.io/docs/akka/current/general/addressing.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM