Akka不会自动加入种子节点

时间:2014-01-09 02:27:51

标签: scala playframework playframework-2.0 akka akka-cluster

我用play app定义了一个akka集群。

application.conf

akka {
  actor {
    provider = "akka.cluster.ClusterActorRefProvider"
  }
  remote {
    log-remote-lifecycle-events = off
    netty.tcp {
      hostname = "192.168.1.100"
      port = 2552
    }
  }
  cluster {
    seed-nodes = [
      "akka.tcp://application@192.168.1.100:2552",
      "akka.tcp://application@192.168.1.101:2552",
      "akka.tcp://application@192.168.1.102:2552"]
      auto-down-unreachable-after = 10s
  }
}

然后我定义了一个集群监听器

class ClusterListener extends Actor with ActorLogging {
  def receive = {
    case state: CurrentClusterState =>
      log.info("Current members: {}", state.members.mkString(", "))
    case MemberUp(member) =>
      log.info("Member is Up: {}", member.address)
    case UnreachableMember(member) =>
      log.info("Member detected as unreachable: {}", member)
    case MemberRemoved(member, previousStatus) =>
      log.info("Member is Removed: {} after {}",
        member.address, previousStatus)
    case _: ClusterDomainEvent => // ignore
  }
}

然后像这样启动我的应用

val clusterListener = Akka.system.actorOf(Props[ClusterListener], "cluster-listener")
  Cluster(Akka.system).subscribe(clusterListener, classOf[ClusterDomainEvent])

我首先在192.168.1.100上启动应用程序,它加入了。

  

然后我在192.16.1.101192.16.1.102上启动相同的应用。

但第一个种子节点从未收到加入事件!

  

如何让其他节点加入此群集?

1 个答案:

答案 0 :(得分:2)

我找到了原因。群集在对象中定义。并且对象是惰性初始化的,所以只需在Global.scala中调用该对象的任何方法。傻傻的我!!!