Search code examples
scalaakkaakka-remote-actor

how to give the accurate path to find the remote actor


I am following this tutorial

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

I am following it as it is but my program is not running it gives me errors and i am confused about this line :

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

What do i have to write in place of "user" ? When I write the full path to the end for example:

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

and run both hellolocal and helloremote both give me errors about looking up the actor for that address.

and if i write the code as it is it gives me error 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'.

Solution

  • An remote akka actor path is made up of the following components:

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

    So for the first example, those components end up being:

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

    All actors started by you in your custom actor code will roll up under the user root. Akka uses another root called system for system level actors. These actors fall under a separate hierarchy and supervision scheme from the custom ones that a user needs for their custom application. So user should always be part of the path to the custom RemoteActor from the example. Then, because RemoteActor is started as a top level actor (no direct supervisor, started from system as opposed to the context of another actor) with a name = "RemoteActor" it will roll up under the path /user/RemoteActor. So putting it all together, the path to use to remotely lookup that actor is the one given in the example code:

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