How do I create an actor with a different path?

If you create an actor (no name), it will live on the way akka.tcp://system@192.168.1.2:2552/user/$a#-576914160

. myGpurp

Is it possible to create an actor directly in a subdirectory ? For example. result: the path to the object will be akka.tcp://system@192.168.1.2:2552/user/myGpurp/$a#-576914160

.

+3


source to share


2 answers


You need to create an actor with a name myGpurp

and then ask the actor to create a child. This is the only way to get the path you want.



+4


source


First you need to create named actor myGpurp:

val myGpurp: ActorRef = context.actorOf(Props(classOf[myGpurp]),"myGpurp")

      

In MyGpurp, you can create an anonymous or named actor:



import akka.actor.{Actor, ActorRef, Props}

class MyGpurp extends Actor {
  override def receive: Receive = {
    case m: Any =>
      val child: ActorRef = context.actorOf(Props(classOf[SomeActor]))
      child ! "Message"
  }
}

      

The path to your SomeActor will be like akka.tcp: // system@192.168.1.2 : 2552 / user / myGpurp / $ a # -576914160

+4


source







All Articles