How do I mix typed and untyped actors?

How do I mix typed and untyped actors ? As I understood I have to specify main actor when I create instance of ActorSystem like this

val system: akka.typed.ActorSystem[Start] = akka.typed.ActorSystem("main", Props(mainBehaviour))

On the other hand I use akka-http which is initialized like this

implicit val system = ActorSystem()
implicit val executor = system.dispatcher
implicit val materializer = ActorMaterializer()
// etc...

I see that I can create typed system from untyped system by calling

object ActorSystem {
  def apply(untyped: akka.actor.ActorSystem): ActorSystem[Nothing] = new Wrapper(untyped.asInstanceOf[ExtendedActorSystem])
}

So assuming I did

val typeSystem = akka.typed.ActorSystem(untypedSystem)

how do I create my first typed actor from typeSystem ? There is no typed ActorContext whose actorOf I can call.

Other materials I've read on the subject are

  • http://blog.scalac.io/2015/04/30/leszek-akka-typed.html
  • http://www.slideshare.net/ktoso/fresh-from-the-oven-042015-experimental-akka-typed-and-akka-streams
  • https://github.com/rubendg/innovation-day-akka-typed

  • Good catch, this is currently not conveniently possible: what you would need to do is to create the typed ActorSystem and then access the underlying untyped one in order to start the HTTP extension, but the underlying method is private[akka] . You could access this by placing some helper code in your project within the Akka namespace, or you could go the other way around:

    implicit val untyped = akka.actor.ActorSystem("main")
    import untyped.dispatcher
    implicit val mat = ActorMaterializer()
    
    import akka.typed.Ops._
    val typedRef = untyped.spawn(Props(mainBehaviour))
    val typedSys = ActorSystem(untyped)
    
    Http().bind(...) // and send things to typed
    
    链接地址: http://www.djcxy.com/p/27784.html

    上一篇: 如何在vis.js中为我的堆积条形图定义自定义颜色?

    下一篇: 我如何混合打字和非打字的演员?