scalaakkaakka-typed

Scala Akka how to create a Typed ActorContext in route


I am pretty new in Scala Akka . Say I am spawning a Configuration child actor,

object Configuration {
 
  def apply(): Behavior[ConfigurationMessage] = Behaviors.setup(context => new Configuration(context))
 
} 

Now I need same context ActorContext[ConfigurationMessage] in my HTTP router to do some operation.

How can I create the same ActorContext there


Solution

  • The ActorContext cannot be used outside of the actor it's associated with, including in an HTTP router. Any ActorContext which leaks out of an actor (e.g. by sending it as a message) will, by design, throw an exception and not do anything for most operations if it's used outside of its actor.

    The only operations on the ActorContext which could possibly be used outside of the associated actor are: