0

我正在关注本教程

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 错误:

[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'.
4

2 回答 2

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 使用另一个称为system系统级参与者的根。这些参与者属于一个单独的层次结构和监督方案,与用户为其自定义应用程序所需的自定义方案不同。因此,user应该始终是RemoteActor示例中自定义路径的一部分。然后,因为RemoteActor是作为顶级参与者(没有直接主管,从而system不是context另一个参与者开始)开始的,name = "RemoteActor"所以它会在路径下滚动/user/RemoteActor。综上所述,用于远程查找该参与者的路径是示例代码中给出的路径:

"akka://HelloRemoteSystem@127.0.0.1:5150/user/RemoteActor"
于 2014-10-27T12:23:56.950 回答
0

您无需更改“用户”

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

于 2014-10-27T12:16:56.133 回答