【问题标题】:AKKA Remote Actor ErrorAKKA 远程演员错误
【发布时间】:2016-02-14 17:40:02
【问题描述】:

我正在尝试通过

运行 AKKA 远程示例
1. Running the remote actor in a machine with IP 192.168.1.7
2. Running the local from my machine

远程actor在机器中启动(ip地址为192.168.1.7);但是当我从我的机器启动本地演员时,它无法连接到远程演员。请查找本地和远程参与者系统配置:

本地:

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
  }
}

本地系统中连接远程actor的代码:

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
        }
  }
}  

当我启动本地系统时,我收到以下消息:

C:\Users\AnandKrishnan\Documents\GitHub\AkkaRemoteActorsHelloWorld\HelloLocal [master +0 ~5 -0]> sbt run
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=256m; support was removed in 8.0
[info] Set current project to HelloLocal (in build file:/C:/Users/AnandKrishnan/Documents/GitHub/AkkaRemoteActorsHelloWorld/HelloLocal/)
[info] Compiling 1 Scala source to C:\Users\AnandKrishnan\Documents\GitHub\AkkaRemoteActorsHelloWorld\HelloLocal\target\scala-2.11\classes...
[warn] there was one deprecation warning; re-run with -deprecation for details
[warn] one warning found
[info] Running local.Local
[INFO] [02/14/2016 22:57:11.755] [run-main-0] [Remoting] Starting remoting
[INFO] [02/14/2016 22:57:12.163] [run-main-0] [Remoting] Remoting started; listening on addresses :[akka.tcp://LocalSystem@127.0.0.1:50830]
[INFO] [02/14/2016 22:57:12.163] [run-main-0] [Remoting] Remoting now listens on addresses: [akka.tcp://LocalSystem@127.0.0.1:50830]
[WARN] [02/14/2016 22:57:13.351] [LocalSystem-akka.remote.default-remote-dispatcher-5] [akka.tcp://LocalSystem@127.0.0.1:50830/system/endpointManager/reliableEndpointWriter-akka.tcp
%3A%2F%2FHelloRemoteSystem%40192.168.1.7%3A5150-0/endpointWriter] AssociationError [akka.tcp://LocalSystem@127.0.0.1:50830] -> [akka.tcp://HelloRemoteSystem@192.168.1.7:5150]: Error
 [Invalid address: akka.tcp://HelloRemoteSystem@192.168.1.7:5150] [
akka.remote.InvalidAssociation: Invalid address: akka.tcp://HelloRemoteSystem@192.168.1.7:5150
Caused by: akka.remote.transport.Transport$InvalidAssociationException: Connection refused: no further information: /192.168.1.7:5150
]
[WARN] [02/14/2016 22:57:13.371] [LocalSystem-akka.remote.default-remote-dispatcher-6] [Remoting] Tried to associate with unreachable remote address [akka.tcp://HelloRemoteSystem@192.168.1.7:5150]. Address is now gated for 5000 ms, all messages to this address will be delivered to dead letters. Reason: Connection refused: no further information: /192.168.1.7:5150
[INFO] [02/14/2016 22:57:13.389] [LocalSystem-akka.actor.default-dispatcher-3] [akka://LocalSystem/deadLetters] Message [java.lang.String] from Actor[akka://LocalSystem/user/LocalActor#1441959988] to Actor[akka://LocalSystem/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'.

【问题讨论】:

  • 你能解决这个问题吗?

标签: scala akka-remote-actor


【解决方案1】:

在 Remote Actor 类中你有:

val system = ActorSystem("HelloRemoteSystem", config)

确保在本地参与者中使用actorSelection/actorFor 时使用相同的名称,例如:

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

【讨论】:

    【解决方案2】:

    为了让 Akka actor 系统与其他主机通信,actor 系统必须绑定到可以被其他主机路由的主机名或 IP。 localhost,当然不是。

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

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

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

    【讨论】:

    • 嗨,我的远程演员正在 192.168.1.7 上运行。同样在创建演员(val remote)时的本地代码中,我遇到了远程IP。您能否更具体地说明我需要更改上述配置的哪个部分?本地会议还是远程会议?
    • 我在同一个例子中遇到了类似的问题。显然,主机名不会被视为与实际 IP 相同。为什么是这样?可以做些什么呢?因为你是对的,所以我更愿意使用主机名。
    • 如果我将远程主机名设置为机器的 IP,那么我会收到一个异常提示 Failed to bind ... cannot assign requested address
    猜你喜欢
    • 2012-05-09
    • 2014-05-28
    • 1970-01-01
    • 2013-09-21
    • 1970-01-01
    • 2012-02-03
    • 2017-05-07
    • 2012-08-08
    • 2014-03-16
    相关资源
    最近更新 更多