bindActorFactory...] not starting up the actor at Play Framework application startup

62 Views Asked by At

I have an Akka Actor named MyActorin in my Scala Play Framework application. I am binding this actor in a module named MyModule

class MyActor @Inject() (system: ActorSystem) extends Actor with ActorLogging {

  override def preStart(): Unit = {
    log.info("[MyActor] Inside preStart")
    system.scheduler.scheduleWithFixedDelay(initialDelay = 5.seconds, delay = 10.seconds, message = "1", receiver = self)(system.dispatcher)
  }
  override def receive: Receive = {
    case "1" => log.info("[MyActor] Received Message")
  }
}
class MyModule extends AbstractModule with AkkaGuiceSupport {
  override def configure(): Unit = {
    bindActor[MyActor]("my-actor")
  }
}

And then in my application.conf I have play.modules.enabled += "com.learning.actors.MyModule"

I have added logs in the actor's preStart() method but none of them are getting printed on application server startup.

I have manually send(!_=) the actor a message to initialize it but this is not the behavior I want. I want it to be up and running as soon as my play application starts.

How do I do that?

0

There are 0 best solutions below