nocturnal
nocturnal

Reputation: 395

is there a way for one Akka node to know if the other akka node got restarted

I have a akka node (say A) which does the bootstrapping and once done sends a message to other akka Node (say B), only then Node B will start doing its job. Now the problem is, say Node A sent bootstrapping message to Node B and then Node B got restarted, so when Node B came up it will be in waiting state (waiting for Bootstrapping msg from Node A).

Is there a way Node A know that Node B got restarted and sends the message again?

Upvotes: 0

Views: 54

Answers (1)

atline
atline

Reputation: 31584

Three solutions FYI.

1) You can let nodeB send one message to nodeA every time when it starts by using actorSelection. Then nodeA can know nodeB start.

2) Set event listener on nodeA.

object ClusterDomainEventListener {
  def props = Props[ClusterDomainEventListener]
  val name = "clusterDomainEventListener"
}

class ClusterDomainEventListener extends Actor {
  Cluster(context.system).subscribe(self, classOf[ClusterDomainEvent])

  def receive = {
    case MemberUp(m) =>
      println(m.address)
  }
}

NodeA:

system.actorOf(ClusterDomainEventListener.props, ClusterDomainEventListener.name)

Then, every time nodeB start, nodeA will get the MemberUp event, the println output is: akka.tcp://[email protected]:2551, you surely know nodeB is for example run on 10.192.225.18:2559, so you can know B is up. This is a little hard coding.

3) If you can set a role to nodeB akka configure file:

cluster {
  roles = ["nodeB"]

  seed-nodes = [
    "akka.tcp://[email protected]:2551"
  ]
}

then you can reuse method 2, but in case MemberUp(m), you can just use if (m.hasRole("nodeB")) to know B is up, and do next things you want.

Upvotes: 1

Related Questions