【问题标题】:Connect two machines in AKKA remotely ,connection refused远程连接AKKA中的两台机器,连接被拒绝
【发布时间】:2018-11-20 12:14:28
【问题描述】:

我是 akka 的新手,想使用 akka 远程连接两台 PC,只是为了在两者中运行一些代码(2 个参与者)。我已经尝试过akka doc 中的示例。但我真正要做的是将 2 个 IP 地址添加到配置文件中我总是得到这个错误?

第一台机器给我这个错误:

[信息] [错误] [11/20/2018 13:58:48.833] [ClusterSystem-akka.remote.default-remote-dispatcher-6] [akka.remote.artery.Association(akka://ClusterSystem)] 出站 到 [akka://ClusterSystem@192.168.1.2:2552] 的控制流失败。 重新启动它。与 [akka://ClusterSystem@192.168.1.2:2552] 握手 未在 20000 毫秒内完成 (akka.remote.artery.OutboundHandshake$HandshakeTimeoutException: 与 [akka://ClusterSystem@192.168.1.2:2552] 握手没有 在 20000 毫秒内完成)

第二台机器:

线程“main”中的异常 akka.remote.RemoteTransportException:无法将 TCP 绑定到 [192.168.1.3:2552] 由于:绑定失败,因为 java.net.BindException:无法分配请求的地址:绑定

配置文件内容:

akka {
  actor {
    provider = cluster
  }
  remote {
    artery {
      enabled = on
      transport = tcp
      canonical.hostname = "192.168.1.3"
      canonical.port = 0
    }
  }
  cluster {
    seed-nodes = [
      "akka://ClusterSystem@192.168.1.3:2552",
      "akka://ClusterSystem@192.168.1.2:2552"]

    # auto downing is NOT safe for production deployments.
    # you may want to use it during development, read more about it in the docs.
    auto-down-unreachable-after = 120s
  }
}

# Enable metrics extension in akka-cluster-metrics.
akka.extensions=["akka.cluster.metrics.ClusterMetricsExtension"]

# Sigar native library extract location during tests.
# Note: use per-jvm-instance folder when running multiple jvm on one host.
akka.cluster.metrics.native-library-extract-folder=${user.dir}/target/native

【问题讨论】:

  • 首先你需要解决第二台电脑的绑定问题。

标签: scala akka


【解决方案1】:

首先,您不需要为 AKKA 远程添加集群配置。应该使用具体端口而不是“0”来启用 PC 或节点的远程处理,这样您就知道要连接哪个端口。

有以下配置

PC1

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

PC2

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

使用下面的actor路径将远程中的任何actor从PC1连接到PC2

akka://<PC2-ActorSystem>@192.168.1.4:18000/user/<actor deployed in PC2>

使用下面的actor路径从PC2连接到PC1

akka://<PC2-ActorSystem>@192.168.1.3:19000/user/<actor deployed in PC1>

端口号和 IP 地址为示例。

【讨论】:

  • 谢谢。我能知道在哪里添加演员路径,是在 conf 文件中吗?如果是,语法是什么?
  • 我认为您需要了解 AKKA 和 Actor 模型的基础知识。你可以谷歌或者你可以看看这个教程javatpoint.com/akka-tutorial
猜你喜欢
  • 2020-10-26
  • 1970-01-01
  • 2016-03-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-08-02
  • 2017-08-08
  • 1970-01-01
相关资源
最近更新 更多