Scala AKKA远程执行器错误

Scala AKKA远程执行器错误,scala,akka-remote-actor,Scala,Akka Remote Actor,我正在尝试运行一个AKKA远程示例 1. Running the remote actor in a machine with IP 192.168.1.7 2. Running the local from my machine 远程参与者在机器中启动(ip地址为192.168.1.7);但是当我从我的机器启动本地actor时,它无法连接到远程actor。请查找本地和远程actor系统配置: 本地: akka { //loglevel = "INFO" actor { pro

我正在尝试运行一个AKKA远程示例

1. Running the remote actor in a machine with IP 192.168.1.7
2. Running the local from my machine
远程参与者在机器中启动(ip地址为192.168.1.7);但是当我从我的机器启动本地actor时,它无法连接到远程actor。请查找本地和远程actor系统配置:

本地:

akka {
  //loglevel = "INFO"
  actor {
    provider = "akka.remote.RemoteActorRefProvider"
  }
  remote {
    enabled-transports = ["akka.remote.netty.tcp"]
    netty.tcp {
      hostname = "127.0.0.1"
      port = 0
    }
    //log-sent-messages = on
    //log-received-messages = on
  }
}
远程:

akka {
  //loglevel = "INFO"
  actor {
    provider = "akka.remote.RemoteActorRefProvider"
  }
  remote {
    enabled-transports = ["akka.remote.netty.tcp"]
    netty.tcp {
      hostname = "127.0.0.1"
      port = 5150
    }
    //log-sent-messages = on
    //log-received-messages = on
  }
}
要连接到远程参与者的本地系统中的代码:

class LocalActor extends Actor {
  val remote = context.actorFor("akka.tcp://HelloRemoteSystem@192.168.1.7:5150/user/RemoteActor")
  var counter = 0
  def receive = {
    case "START" => 
        remote ! "Hello from the LocalActor"
    case msg: String => 
        println(s"LocalActor received message: '$msg'")
        if (counter < 5) {
            sender ! "Hello back to you"
            counter += 1
        }
  }
}  

为了让Akka actor系统与其他主机通信,actor系统必须绑定到可由其他主机路由的主机名或IP<代码>本地主机当然不是

您的远程系统需要绑定到192.168.1.7:

akka {
  remote {
    netty.tcp {
      hostname = "192.168.1.7"
    }
  }
}

当然,在生产环境中,您可能希望使用主机名而不是IP。

在远程参与者类中,您有:

val system = ActorSystem("HelloRemoteSystem", config)
确保在本地actor中使用
actorSelection
/
actorFor
时使用相同的名称,如:

val remoteActor = context.actorSelection("akka.tcp://HelloRemoteSystem@127.0.0.1:2553/user/RemoteActor")

嗨,我的远程演员正在192.168.1.7上运行。在创建actor(val remote)的本地代码中,我遇到了远程IP。你能不能更具体一点,在上面的配置中,我需要对哪个部分进行更改?本地配置还是远程配置?我在这个例子中遇到了类似的问题。显然,主机名并没有得到与实际IP相同的处理。为什么会这样?我们能做些什么呢?因为你是对的,我更愿意使用主机名。如果我将远程主机名设置为机器的IP,则会出现异常,说
绑定失败…
无法分配请求的地址。
。你能解决此问题吗?
val remoteActor = context.actorSelection("akka.tcp://HelloRemoteSystem@127.0.0.1:2553/user/RemoteActor")