【问题标题】:Akka remote : trying to connect two machinesAkka远程:尝试连接两台机器
【发布时间】:2020-10-26 21:39:03
【问题描述】:

我有两台不同的物理机器(192.168.1.37 和 192.168.1.99),我可以很容易地从另一台机器上 ping 每一台机器。 我正在尝试将它们与 Akka 远程连接(我正在使用 Java)

我的本​​地机器(试图向远程机器上的演员发送消息):

akka {
  actor {
    provider = remote
  }
  
  remote {
    artery {
      enabled = on
      transport = tcp
      canonical.hostname = "192.168.1.37"
      canonical.port = 2556
    }
  }
}

还有代码:

ActorSystem system = ActorSystem.create("local", ConfigFactory.load("akka.conf"));
ActorSelection selection = system.actorSelection("akka://remote@192.168.1.99:2555/user/actor");
selection.tell("trying to connect...", ActorRef.noSender());

现在我的远程机器的配置(我在启动本地机器之前启动它):

akka {
  actor {
    provider = remote
  }
  
  remote {
    artery {
      enabled = on
      transport = tcp
      canonical.hostname = "192.168.1.99"
      canonical.port = 2555
    }
  }
}

还有代码:

ActorSystem system = ActorSystem.create("remote", ConfigFactory.load("akka.conf"));
ActorRef actor = system.actorOf(Props.create(SimpleActor.class),"actor");

然后我运行远程 JVM,然后启动本地 JVM。这是我为本地日志获取的日志:

[INFO] [07/06/2020 19:42:06.950] [main] [akka.remote.artery.tcp.ArteryTcpTransport(akka://local)] Remoting started with transport [Artery tcp]; listening on address [akka://local@192.168.1.37:2556] with UID [-6291059934924481437]
[WARN] [07/06/2020 19:42:12.653] [local-akka.remote.default-remote-dispatcher-7] [akka.stream.Log(akka://local/system/StreamSupervisor-0)] [outbound connection to [akka://remote@192.168.1.99:2555], message stream] Upstream failed, cause: StreamTcpException: Tcp command [Connect(192.168.1.99/<unresolved>:2555,None,List(),Some(5000 milliseconds),true)] failed because of akka.io.TcpOutgoingConnection$$anon$2: Connect timeout of Some(5000 milliseconds) expired
[WARN] [07/06/2020 19:42:12.653] [local-akka.remote.default-remote-dispatcher-4] [akka.stream.Log(akka://local/system/StreamSupervisor-0)] [outbound connection to [akka://remote@192.168.1.99:2555], control stream] Upstream failed, cause: StreamTcpException: Tcp command [Connect(192.168.1.99/<unresolved>:2555,None,List(),Some(5000 milliseconds),true)] failed because of akka.io.TcpOutgoingConnection$$anon$2: Connect timeout of Some(5000 milliseconds) expired
[WARN] [07/06/2020 19:42:12.655] [local-akka.remote.default-remote-dispatcher-4] [RestartWithBackoffFlow(akka://local)] Restarting graph due to failure. stack_trace:  (akka.stream.StreamTcpException: Tcp command [Connect(192.168.1.99/<unresolved>:2555,None,List(),Some(5000 milliseconds),true)] failed because of akka.io.TcpOutgoingConnection$$anon$2: Connect timeout of Some(5000 milliseconds) expired)
[WARN] [07/06/2020 19:42:12.655] [local-akka.remote.default-remote-dispatcher-7] [RestartWithBackoffFlow(akka://local)] Restarting graph due to failure. stack_trace:  (akka.stream.StreamTcpException: Tcp command [Connect(192.168.1.99/<unresolved>:2555,None,List(),Some(5000 milliseconds),true)] failed because of akka.io.TcpOutgoingConnection$$anon$2: Connect timeout of Some(5000 milliseconds) expired)
[WARN] [07/06/2020 19:42:19.349] [local-akka.remote.default-remote-dispatcher-7] [akka.stream.Log(akka://local/system/StreamSupervisor-0)] [outbound connection to [akka://remote@192.168.1.99:2555], message stream] Upstream failed, cause: StreamTcpException: Tcp command [Connect(192.168.1.99/<unresolved>:2555,None,List(),Some(5000 milliseconds),true)] failed because of akka.io.TcpOutgoingConnection$$anon$2: Connect timeout of Some(5000 milliseconds) expired
[WARN] [07/06/2020 19:42:19.350] [local-akka.remote.default-remote-dispatcher-7] [RestartWithBackoffFlow(akka://local)] Restarting graph due to failure. stack_trace:  (akka.stream.StreamTcpException: Tcp command [Connect(192.168.1.99/<unresolved>:2555,None,List(),Some(5000 milliseconds),true)] failed because of akka.io.TcpOutgoingConnection$$anon$2: Connect timeout of Some(5000 milliseconds) expired)
[WARN] [07/06/2020 19:42:20.346] [local-akka.remote.default-remote-dispatcher-7] [akka.stream.Log(akka://local/system/StreamSupervisor-0)] [outbound connection to [akka://remote@192.168.1.99:2555], control stream] Upstream failed, cause: StreamTcpException: Tcp command [Connect(192.168.1.99/<unresolved>:2555,None,List(),Some(5000 milliseconds),true)] failed because of akka.io.TcpOutgoingConnection$$anon$2: Connect timeout of Some(5000 milliseconds) expired
[WARN] [07/06/2020 19:42:20.346] [local-akka.remote.default-remote-dispatcher-7] [RestartWithBackoffFlow(akka://local)] Restarting graph due to failure. stack_trace:  (akka.stream.StreamTcpException: Tcp command [Connect(192.168.1.99/<unresolved>:2555,None,List(),Some(5000 milliseconds),true)] failed because of akka.io.TcpOutgoingConnection$$anon$2: Connect timeout of Some(5000 milliseconds) expired)
[WARN] [07/06/2020 19:42:26.365] [local-akka.remote.default-remote-dispatcher-4] [akka.stream.Log(akka://local/system/StreamSupervisor-0)] [outbound connection to [akka://remote@192.168.1.99:2555], message stream] Upstream failed, cause: StreamTcpException: Tcp command [Connect(192.168.1.99/<unresolved>:2555,None,List(),Some(5000 milliseconds),true)] failed because of akka.io.TcpOutgoingConnection$$anon$2: Connect timeout of Some(5000 milliseconds) expired
[WARN] [07/06/2020 19:42:26.366] [local-akka.remote.default-remote-dispatcher-4] [RestartWithBackoffFlow(akka://local)] Restarting graph due to failure. stack_trace:  (akka.stream.StreamTcpException: Tcp command [Connect(192.168.1.99/<unresolved>:2555,None,List(),Some(5000 milliseconds),true)] failed because of akka.io.TcpOutgoingConnection$$anon$2: Connect timeout of Some(5000 milliseconds) expired)
[WARN] [07/06/2020 19:42:27.331] [local-akka.remote.default-remote-dispatcher-7] [akka.stream.Log(akka://local/system/StreamSupervisor-0)] [outbound connection to [akka://remote@192.168.1.99:2555], control stream] Upstream failed, cause: OutboundHandshake$HandshakeTimeoutException: Handshake with [akka://remote@192.168.1.99:2555] did not complete within 20000 ms
[INFO] [07/06/2020 19:42:27.335] [local-akka.actor.default-dispatcher-3] [akka://local/deadLetters] Message [java.lang.String] without sender to Actor[akka://local/deadLetters] was not delivered. [1] dead letters encountered. If this is not an expected behavior, then [Actor[akka://local/deadLetters]] may have terminated unexpectedly, This logging can be turned off or adjusted with configuration settings 'akka.log-dead-letters' and 'akka.log-dead-letters-during-shutdown'.
[ERROR] [07/06/2020 19:42:27.342] [local-akka.remote.default-remote-dispatcher-7] [akka.remote.artery.Association(akka://local)] Outbound message stream to [akka://remote@192.168.1.99:2555] failed. Restarting it. Handshake with [akka://remote@192.168.1.99:2555] did not complete within 20000 ms (akka.remote.artery.OutboundHandshake$HandshakeTimeoutException: Handshake with [akka://remote@192.168.1.99:2555] did not complete within 20000 ms)
[ERROR] [07/06/2020 19:42:27.348] [local-akka.remote.default-remote-dispatcher-7] [akka.remote.artery.Association(akka://local)] Outbound control stream to [akka://remote@192.168.1.99:2555] failed. Restarting it. Handshake with [akka://remote@192.168.1.99:2555] did not complete within 20000 ms (akka.remote.artery.OutboundHandshake$HandshakeTimeoutException: Handshake with [akka://remote@192.168.1.99:2555] did not complete within 20000 ms)

【问题讨论】:

  • 我建议使用 akka-cluster,或者在你的服务节点上创建一个 akka-http 或 akka-grpc 服务,以便与其他服务进行通信,而不是使用 akka 远程处理本身。经典的 akka 远程处理已被弃用。请参阅文档中此页面顶部的建议。 doc.akka.io/docs/akka/current/remoting-artery.html

标签: scala akka akka-cluster


【解决方案1】:

您的示例看起来不错。我有一个对 2 个 JVM 做同样的事情,但在同一台机器上。我建议的第一件事是只在一台机器上测试所有东西,但要在不同的 JVM 上测试。如果它有效,那么你有 2 台机器。这里我建议先检查端口,因为 ping 不使用 TCP。检查这个问题: https://networkengineering.stackexchange.com/a/37897/72199

标准 ping 命令不使用 TCP 或 UDP。它使用 ICMP。更准确地说,使用了 ICMP 类型 8(回声消息)和类型 0(回声回复消息)。 ICMP 没有端口!

有关详细信息,请参阅 RFC792。

我的建议是你可以使用 telnet 测试特定的端口:

打开命令提示符 在每台机器上输入“telnet” 例如,我们将从 192.168.1.37 键入“telnet 192.168.1.99 2555”,反之亦然。 如果出现空白屏幕,则端口已打开,测试成功。 如果您收到正在连接... 消息或错误消息,则表明该端口被阻塞。

除此之外,使用akka集群更容易......

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-08
    • 1970-01-01
    • 2018-03-03
    • 2012-06-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多