Akka - cluster aware router doesn't starts nodes

182 views Asked by At

I need to create a cluster of 3 nodes where each node will run one instance of an actor -TestActor. I want that the router will create the nodes by itself(pool) but that the first one it creats will be the seed node since the routees will be the first actors created in the cluster.

This is my code TestActor.scala :

import akka.actor.{Actor, ActorLogging, ActorSystem, Props}
import akka.cluster.Cluster
import akka.routing.FromConfig
import com.typesafe.config.ConfigFactory
import akka.pattern.ask
import akka.util.Timeout
import scala.concurrent.ExecutionContext.Implicits.global

object TestActor {
  def main(args: Array[String]) {
    val system = ActorSystem("mySys", ConfigFactory.load("test"))
    val testActor = system.actorOf(Props(classOf[TestActor]).withRouter(FromConfig()),"TestActor")
    implicit val t = Timeout(60 * 1000)
    println((testActor ? "hello").onSuccess{
      case x=> println(x)
    })
  }
}
class TestActor extends Actor with ActorLogging {

  Cluster(system)

  override def postStop(): Unit = {
    log.info(s"Stopping actor on path ${self.path}")
    super.postStop()
  }

  override def preStart(): Unit ={
    log.info(s"Starting actor on path ${self.path}")
    super.preStart()
  }

  override def receive : Receive = {
    case x => {
     log.info(s"actor : ${self.path} GOT MESSAGE  $x")
     sender() ! x
   }
  }

}

and test.conf :

   akka {
   cluster {
     auto-down-unreachable-after = 20s
     seed-nodes = [
       "akka.tcp://[email protected]:2552"
     ]
   }
   actor {
     provider = "akka.cluster.ClusterActorRefProvider"

     deployment {
       /TestActor {
         router = round-robin-pool
         nr-of-instances = 3
         cluster {
           enabled = on
           max-nr-of-instances-per-node = 1
           allow-local-routees = off
         }
       }
     }
   }
 }

Then when I run the program I don't see any prints and the message goes to deadLetters.

Here is the log:

[INFO] [01/08/2017 13:29:17.967] [main] [Remoting] Starting remoting
[INFO] [01/08/2017 13:29:18.290] [main] [Remoting] Remoting started; listening on addresses :[akka.tcp://[email protected]:2552]
[INFO] [01/08/2017 13:29:18.292] [main] [Remoting] Remoting now listens on addresses: [akka.tcp://[email protected]:2552]
[INFO] [01/08/2017 13:29:18.301] [main] [Cluster(akka://mySys)] Cluster Node [akka.tcp://[email protected]:2552] - Starting up...
[INFO] [01/08/2017 13:29:18.366] [main] [Cluster(akka://mySys)] Cluster Node [akka.tcp://[email protected]:2552] - Registered cluster JMX MBean [akka:type=Cluster]
[INFO] [01/08/2017 13:29:18.366] [main] [Cluster(akka://mySys)] Cluster Node [akka.tcp://[email protected]:2552] - Started up successfully
[INFO] [01/08/2017 13:29:18.374] [mySys-akka.actor.default-dispatcher-2] [Cluster(akka://mySys)] Cluster Node [akka.tcp://[email protected]:2552] - 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] [01/08/2017 13:29:18.375] [mySys-akka.actor.default-dispatcher-2] [Cluster(akka://mySys)] Cluster Node [akka.tcp://[email protected]:2552] - Metrics collection has started successfully
()
[INFO] [01/08/2017 13:29:18.382] [mySys-akka.actor.default-dispatcher-2] [akka://mySys/deadLetters] Message [java.lang.String] from Actor[akka://mySys/temp/$a] to Actor[akka://mySys/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'.
[INFO] [01/08/2017 13:29:18.387] [mySys-akka.actor.default-dispatcher-5] [Cluster(akka://mySys)] Cluster Node [akka.tcp://[email protected]:2552] - Node [akka.tcp://[email protected]:2552] is JOINING, roles []
[INFO] [01/08/2017 13:29:19.399] [mySys-akka.actor.default-dispatcher-3] [Cluster(akka://mySys)] Cluster Node [akka.tcp://[email protected]:2552] - Leader is moving node [akka.tcp://[email protected]:2552] to [Up]
0

There are 0 answers