InvalidActorNameException - actor name {name} is not unique

So, I'm starting to use Akka actors in my Play 2.0 app. I quickly noticed that repeated calls to send messages to the same actor specified through:

val myActor = Akka.system.actorOf(Props[MyActor], name = "myactor") 

The result is an InvalidActorNameException .

Then I started reading about creating Actors in this doc

Doc seemed to recommend creating the Actor's master class with all the individual participants listed there. receive this actor class, in turn, will correspond to the message and delegate the message to the corresponding player.

So, I tried this and now I have something like:

 class MasterActor extends Actor{ import context._ val emailActor = actorOf(Props[EmailActor], name = "emailActor") protected def receive = { case reminder : BirthdayReminder => emailActor ! reminder } } 

The problem is that I am in the same situation as before. I don't know how to avoid an InvalidActorNameException when I try something like:

  val myActor = Akka.system.actorOf(Props[MasterActor], name = "MasterActor") myActor ! BirthdayReminder(someBirthday) 

So what is the right way to organize my actors?

+4
source share
1 answer

If you only need one MasterActor, why are you creating several? You should just find the one you have already created:

 val actorRef = context.actorFor("MasterActor") actorRef ! BirthdayReminder(someBirthday) 
+2
source

All Articles