jilen
jilen

Reputation: 5763

Akka not automatically join seed nodes

I define an akka cluster with play app.

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://[email protected]:2552",
      "akka.tcp://[email protected]:2552",
      "akka.tcp://[email protected]:2552"]
      auto-down-unreachable-after = 10s
  }
}

Then I define a cluster listener

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

And start my app like this

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

I firstly start the app on 192.168.1.100, it joins.

Then I start the same app on 192.16.1.101 and 192.16.1.102.

But the first seed node never receive a join event!

What should I do, to let the other nodes join this cluster ?

Upvotes: 1

Views: 1507

Answers (1)

jilen
jilen

Reputation: 5763

I found the reason. The cluster is defined in an object. And object are lazy initialized, So just call any method of that object at the Global.scala. Silly me!!!

Upvotes: 3

Related Questions