Akka Typed - integration with untyped

Hi everyone.

I’ve encountered following issue:

import akka.actor.typed.ActorSystem
import akka.actor.typed.scaladsl.Behaviors
import akka.actor.typed.scaladsl.adapter._

object Bug2 extends App {
  val system = ActorSystem(Behaviors.ignore, "TopLevel")
  system.toUntyped.spawn(Behaviors.ignore, "Another")
}

If I convert typed actor system to untyped and than try to spawn behavior in that, it throws an exception:

Exception in thread "main" java.lang.UnsupportedOperationException: cannot create top-level actor [client-consumer-packet-id-allocator-0] from the outside on ActorSystem with custom user guardian
at akka.actor.ActorSystemImpl.actorOf(ActorSystem.scala:780)
at akka.actor.typed.internal.adapter.ActorRefFactoryAdapter$.spawn(ActorRefFactoryAdapter.scala:40)
at akka.actor.typed.scaladsl.adapter.package$UntypedActorSystemOps$.spawn$extension(package.scala:67)
at akka.stream.alpakka.mqtt.streaming.scaladsl.ActorMqttClientSession.<init>(MqttSession.scala:117)
at akka.stream.alpakka.mqtt.streaming.scaladsl.ActorMqttClientSession$.apply(MqttSession.scala:82)
at Bug$.delayedEndpoint$Bug$1(Bug.scala:12)
at Bug$delayedInit$body.apply(Bug.scala:7)
at scala.Function0.apply$mcV$sp(Function0.scala:39)
at scala.Function0.apply$mcV$sp$(Function0.scala:39)
at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:17)
at scala.App.$anonfun$main$1(App.scala:75)
at scala.App.$anonfun$main$1$adapted(App.scala:75)
at scala.collection.IterableOnceOps.foreach(IterableOnce.scala:576)
at scala.collection.IterableOnceOps.foreach$(IterableOnce.scala:574)
at scala.collection.AbstractIterable.foreach(Iterable.scala:904)
at scala.App.main(App.scala:75)
at scala.App.main$(App.scala:73)
at Bug$.main(Bug.scala:7)
at Bug.main(Bug.scala)

This is actually the root cause of an issue with Alpakka MQTT connector, when I’m trying to use it with Akka Typed: #1836. Under the hood, Alpakka MQTT tries to create some actors when initialized and it uses adapter DSL to spawn behaviour.

I haven’t opened issue in Akka tracker yet, as I am not sure the code above is valid usage scenario. Do you think the snipped above should work or that’s expected for it to fail?

Thanks

Then you would have to create an akka.actor.ActorSystem to begin with, instead of akka.actor.typed.ActorSystem

The reason is that the akka.actor.typed.ActorSystem only supports one top level actor, the one provided by guardian parameter. Then system.actorOf is not allowed.

A library like Alpakka should use system.systemActorOf so please report an issue in the Alpakka issue tracker.