Search code examples
akkasprayakka-httpakka-cluster

use actorSelection with ask pattern for actors like /temp/$a


I have an ActorSystem(e.g. A) which spawns other ActorSystem (e.g B). When B comes up, it knows the address of A and he executes cluster.join(). Once, the cluster is joined, actors can communicate with each other.

In my scenario:

  • I have a REST request coming to Spray framework to spawn a new ActorSystem.
  • In the request handler, I do an ask(?) to ActorSystem A
  • "A" receives the message, I store the Address of ask(?) request to DB. It is a temp actor something like "akka://ActorSystemA/temp/$a"
  • "A" spawns a new JVM with ActorSystem "B"
  • As soon as "B" comes up and "A" gets a MemberUp message. I pick the ask temporary actorRef from DB and try to send a response back using something like

    context.actorSelection("akka://ActorSystemA/temp/$a").resolveOne(3.seconds) ! Success

but it doesn't work. It always timesout

I tried adding a watch on the temp actor. The actor is not terminated, yet I cannot communicate.

Is this approach correct? Also, why I am getting timeout always.


Solution

  • It turns out that storing temporary references is a bad idea. You should never do it. I changed my design to get around this problem.