javaakkaakka-remote-actorakka-remoting

Akka Client actor connecting to Server actor system


I have server actor running in the background. The basic operation of the server actor is to get a key and a value pair. Once it receives the pair, it stores it in a map and returns it when asked. Now, I have a client actor. I want to the connect to the server actor using actorSelection() method. But I am confused with the parameters it takes. Can anyone help me understand what parameters it takes ?

Server side:- Actor System: actorSystem Server Actor: akkademy-db

Client side:- Actor System: LocalSystem


Solution

  • You didn't mention that your scenario is from the book Learning Akka. As stated in the book, the client can obtain an ActorSelection of the server with the following:

    ActorSelection remoteDb = system.actorSelection("akka.tcp://akkademy@" + remoteAddress + "/user/akkademy-db")
    

    The template for the path, as the documentation describes, is the following:

    akka.<protocol>://<actor system name>@<hostname>:<port>/<actor path>
    

    Using the template, here's a breakdown of the ActorSelection path to the server:

    "akka.tcp://akkademy@" + remoteAddress + "/user/akkademy-db"
    //   tcp               --> protocol
    //   akkademy          --> actor system name
    //   remoteAddress     --> hostname:port
    //   /user/akkademy-db --> actor path
    

    Read the documentation for more information.