连接到Server actor系统的Akka Client actor

时间:2018-03-09 18:23:40

标签: java akka akka-remote-actor akka-remoting

我有服务器actor在后台运行。服务器actor的基本操作是获取密钥和值对。一旦收到该对,它就会将其存储在地图中并在被询问时将其返回。 现在,我有一个客户演员。我想使用actorSelection()方法连接到服务器actor。但我对它所需的参数感到困惑。任何人都可以帮我理解它需要什么参数吗?

服务器端: - 演员系统:actorSystem 服务器角色:akkademy-db

客户方: - 演员系统:LocalSystem

1 个答案:

答案 0 :(得分:1)

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.