如何给出找到远程actor的准确路径

时间:2014-10-27 11:57:48

标签: scala akka akka-remote-actor

我正在学习本教程

http://alvinalexander.com/scala/simple-akka-actors-remote-example

我正在关注它,但我的程序没有运行它给了我错误,我对此行感到困惑:

val remote = context.actorFor("akka://HelloRemoteSystem@127.0.0.1:5150/user/RemoteActor")

我必须用什么来代替“用户”?当我将完整路径写到末尾时,例如:

 val remote = context.actorFor("akka://HelloRemoteSystem@127.0.0.1:5150/sw/opt/programs/akka/akkaremoting/RemoteActor")

并且同时运行hellolocal和helloremote都会让我错误地查找该地址的演员。

如果我按原样编写代码,它会给我错误 helloremote erros:

[INFO] [10/27/2014 16:06:23.736] [HelloRemoteSystem-akka.actor.default-dispatcher-2] [akka://HelloRemoteSystem/deadLetters] Message [java.lang.String] from Actor[akka://HelloRemoteSystem/user/RemoteActor#911921687] to Actor[akka://HelloRemoteSystem/deadLetters] was not delivered. [1] dead letters encountered. This logging can be turned off or adjusted with configuration settings 'akka.log-dead-letters' and 'akka.log-dead-letters-during-shutdown'.
^Csarawaheed@ubuntu:/opt/ifkaar/programs/akka/akkaremoting/helloremote$ sbt run
[info] Loading project definition from /opt/ifkaar/programs/akka/akkaremoting/helloremote/project
[info] Set current project to helloremote (in build file:/opt/ifkaar/programs/akka/akkaremoting/helloremote/)
[info] Running HelloRemote 
Remote Actor receive messgage : The remote actor is alive  
[INFO] [10/27/2014 17:24:06.136] [HelloRemoteSystem-akka.actor.default-dispatcher-2] [akka://HelloRemoteSystem/deadLetters] Message [java.lang.String] from Actor[akka://HelloRemoteSystem/user/RemoteActor#-792263999] to Actor[akka://HelloRemoteSystem/deadLetters] was not delivered. [1] dead letters encountered. This logging can be turned off or adjusted with configuration settings 'akka.log-dead-letters' and 'akka.log-dead-letters-during-shutdown'.

hellolocal erros:

[INFO] [10/27/2014 16:06:23.736] [HelloRemoteSystem-akka.actor.default-dispatcher-2] [akka://HelloRemoteSystem/deadLetters] Message [java.lang.String] from Actor[akka://HelloRemoteSystem/user/RemoteActor#911921687] to Actor[akka://HelloRemoteSystem/deadLetters] was not delivered. [1] dead letters encountered. This logging can be turned off or adjusted with configuration settings 'akka.log-dead-letters' and 'akka.log-dead-letters-during-shutdown'.
^Csarawaheed@ubuntu:/opt/ifkaar/programs/akka/akkaremoting/helloremote$ sbt run
[info] Loading project definition from /opt/ifkaar/programs/akka/akkaremoting/helloremote/project
[info] Set current project to helloremote (in build file:/opt/ifkaar/programs/akka/akkaremoting/helloremote/)
[info] Running HelloRemote 
Remote Actor receive messgage : The remote actor is alive  
[INFO] [10/27/2014 17:24:06.136] [HelloRemoteSystem-akka.actor.default-dispatcher-2] [akka://HelloRemoteSystem/deadLetters] Message [java.lang.String] from Actor[akka://HelloRemoteSystem/user/RemoteActor#-792263999] to Actor[akka://HelloRemoteSystem/deadLetters] was not delivered. [1] dead letters encountered. This logging can be turned off or adjusted with configuration settings 'akka.log-dead-letters' and 'akka.log-dead-letters-during-shutdown'.

2 个答案:

答案 0 :(得分:4)

远程akka actor路径由以下组件组成:

protocol:actor system name:server address:remoting port:root path:actor path + name

因此,对于第一个示例,这些组件最终成为:

protocol = akka://
actor system name = HelloRemoteSystem
server address = 127.0.0.1
remoting port = 5150
root path: user
actor path + name = RemoteActor

您自定义演员代码中由您启动的所有演员都将在user根目录下汇总。 Akka为系统级actor使用另一个名为system的根。这些参与者属于与用户自定义应用程序所需的自定义层次结构和监督方案不同的层次结构和监督方案。因此,user应该始终是示例中自定义RemoteActor路径的一部分。然后,因为RemoteActor作为顶级角色(没有直接主管,从system开始,而不是另一个角色的context)而被name = "RemoteActor"启动,因此它将会滚动在/user/RemoteActor路径下。所以把它们放在一起,用于远程查找该actor的路径就是示例代码中给出的路径:

"akka://HelloRemoteSystem@127.0.0.1:5150/user/RemoteActor"

答案 1 :(得分:0)

您无需更改“用户”

如果您查看akka的文档,您会看到“user”是每个actor系统的子目录,其中包含所有与用户相关/用户创建的actor,它不是您用户的名称:)< / p>