2

我是 Akka 的新手,我正在尝试运行一个在 Google Cloud VM 实例上的 localhost 上工作的简单远程操作者。

VM 具有内部和外部 IP。当我启动一个将 IP 设置为外部的演员时,它无法启动。

但是当我这样做时

netty.tcp {
  hostname = "<internal IP>"
  port = 45000

一切开始都很好。

现在很明显,当尝试从另一台机器内部 IP 连接时无法解析,所以我试图使用以下命令查找参与者:

context.actorSelection("akka.tcp://Main@<external IP>:45000/user/app")

并得到以下错误:

[错误] 为非本地收件人 [Akka.tcp://Main@ external IP :45000/]] 丢弃消息 [class akka.actor.ActorSelectionMessage] 到达 [akka.tcp://Main@ external IP : 45000] 入站地址是 [akka.tcp://Main@ internal IP :45000]

最后一部分确实有道理,但我如何让整个事情发挥作用呢?

4

1 回答 1

2

找到了解决方案。

它基于bind-hostname即将推出的 2.4 版本中可用的配置设置:

构建.sbt

resolvers += "Typesafe Snapshots" at "http://repo.akka.io/snapshots/"

libraryDependencies ++= Seq(
  "com.typesafe.akka" %% "akka-actor" % "2.4-SNAPSHOT",
  "com.typesafe.akka" %% "akka-remote" % "2.4-SNAPSHOT"
)

应用程序.conf

akka {
  actor {
    provider = "akka.remote.RemoteActorRefProvider"
  }
  remote {
    enabled-transports = ["akka.remote.netty.tcp"]
    netty.tcp {
      hostname = "external IP"
      port = 45000
      bind-hostname = "internal IP"
    }
 }
}

bind-port如果需要,您也可以指定。

于 2015-06-26T22:32:11.660 回答