【问题标题】:akka simple cluster with two seed nodes具有两个种子节点的 akka 简单集群
【发布时间】:2014-11-16 16:43:25
【问题描述】:

我正在使用 akka 集群 2.3.6

我编译了两个分开的罐子,里面有主类

   val configuration = ConfigFactory.load()
    val bucket = configuration.getString("bucket")
    val system = ActorSystem(bucket,configuration)
    val resultDispatcherActor = system.actorOf(Props(new MyActor)) 

我正在运行两个单独的 jar:

java -Dconfig.file=poc.conf -jar poc.jar

我的 poc.conf 如下:

akka {
  loglevel = INFO
  stdout-loglevel = INFO  
  event-handlers = ["akka.event.Logging$DefaultLogger"]

  actor {    
    provider = "akka.cluster.ClusterActorRefProvider"
       }
  remote{
    enabled-transports = ["akka.remote.netty.tcp"]    
    log-remote-lifecycle-events = off

    netty.tcp {      
      hostname = ""      
      host = "10.0.0.5"     
      port = 2551
    }         
  }
  cluster {
    seed-nodes = [
      "akka.tcp://myCluster@10.0.0.5:2551",
      "akka.tcp://myCluster@10.0.0.5:2552"]
     
  }
}

netty.tcp 内部阻止分配给端口 2551 和部分 2552 的每个第一个应用程序。

但是,当我启动两个 jar 时,每个 jar 都会打印以下日志:

[INFO] [11/16/2014 18:43:53.890] [main] [Remoting] Starting remoting
[INFO] [11/16/2014 18:43:54.739] [main] [Remoting] Remoting started; listening on addresses :[akka.tcp://myCluster@10.0.0.5:2551]
[INFO] [11/16/2014 18:43:54.757] [main] [Cluster(akka://myCluster)] Cluster Node [akka.tcp://myCluster@10.0.0.5:2551] - Starting up...
[INFO] [11/16/2014 18:43:54.848] [main] [Cluster(akka://myCluster)] Cluster Node [akka.tcp://myCluster@10.0.0.5:2551] - Registered cluster JMX MBean [akka:type=Cluster]
[INFO] [11/16/2014 18:43:54.848] [main] [Cluster(akka://myCluster)] Cluster Node [akka.tcp://myCluster@10.0.0.5:2551] - Started up successfully
[INFO] [11/16/2014 18:43:54.858] [myCluster-akka.actor.default-dispatcher-15] [Cluster(akka://myCluster)] Cluster Node [akka.tcp://myCluster@10.0.0.5:2551] - Metrics will be retreived from MBeans, and may be incorrect on some platforms. To increase metric accuracy add the 'sigar.jar' to the classpath and the appropriate platform-specific native libary to 'java.library.path'. Reason: java.lang.ClassNotFoundException: org.hyperic.sigar.Sigar
[INFO] [11/16/2014 18:43:54.863] [myCluster-akka.actor.default-dispatcher-15] [Cluster(akka://myCluster)] Cluster Node [akka.tcp://myCluster@10.0.0.5:2551] - Metrics collection has started successfully
[WARN] [11/16/2014 18:43:54.963] [myCluster-akka.remote.default-remote-dispatcher-6] [Remoting] Tried to associate with unreachable remote address [akka.tcp://myCluster@10.0.0.5:2552]. Address is now gated for 5000 ms, all messages to this address will be delivered to dead letters. Reason: Connection refused: /10.0.0.5:2552
[INFO] [11/16/2014 18:43:54.972] [myCluster-akka.actor.default-dispatcher-16] [akka://myCluster/deadLetters] Message [akka.cluster.InternalClusterAction$InitJoin$] from Actor[akka://myCluster/system/cluster/core/daemon/firstSeedNodeProcess-1#-86755168] to Actor[akka://myCluster/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'.

我做错了什么?

【问题讨论】:

  • 您用于启动每个应用程序的确切命令/设置是什么?就是说这里无法到达akka.tcp://myCluster@10.0.0.5:2552

标签: scala akka akka-cluster


【解决方案1】:

您需要在运行程序时为其提供端口。在这两种情况下,您的 netty.tcp.port 值默认为 2551

如何执行此操作的示例:

// 0 means a random unused port will be assigned
val port = if (args.isEmpty) "0" else args(0)
val config = ConfigFactory.parseString(s"akka.remote.netty.tcp.port=$port") //etc

另外,请参阅cluster samples,了解如何执行此操作的示例。

【讨论】:

    【解决方案2】:
    Make the seed-node to have the same port 2551 and specify under remote as below.
    
    remote{
    transport = "akka.remote.netty.NettyRemoteTransport"
    
    cluster {
        seed-nodes = [
          "akka.tcp://myCluster@10.0.0.5:2551",
          "akka.tcp://myCluster@10.0.0.5:2551"]
         use-dispatcher = cluster-dispatcher 
    
      }
        cluster-dispatcher {
          type = "Dispatcher"
          executor = "fork-join-executor"
          fork-join-executor {
            parallelism-min = 2
            parallelism-max = 4
          }
        }
    

    【讨论】:

    • 在同一个 ip 上使用同一个端口有什么意义?您只是隐藏了第二个应用程序实例尚无法访问的问题
    猜你喜欢
    • 2021-04-27
    • 1970-01-01
    • 2019-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-26
    相关资源
    最近更新 更多