Listening to Dead Letters in Akka-Typed 2.5

I’m using Akka-Typed 2.5 and have an intermittent race condition of sending a message to an actor that has shut down before I received the Terminated message. Since this is an edge case, I figured the simplest way is to listen to DeadLetters and handle the re-create/re-send from there. Since 2.5 doesn’t seem to have a typed event stream, I tried subscripting the classic way via:

      val untyped = context.system.toClassic
      val listener = untyped.actorOf(Props[DeadLetterListener])
      untyped.eventStream.subscribe(listener, classOf[DeadLetter])

However, that dies at untyped.actorOf(Props[DeadLetterListener]) with java.lang.UnsupportedOperationException: cannot create top-level actor from the outside on ActorSystem with custom user guardian.

Is there a different way to subscribe to deadletters in akka-typed 2.5?

I can’t easily upgrade to 2.6 because of a number of breaking changes, the main blocker being that behavior orElse Behaviors.receiveMessagePartial[T] no longer exists which I use extensively as a behavior wrapper for localized logging of Unhandled messages in state machines.

That was simply not covered yet by the in-progress APIs in 2.5.

You should be able to spawn the listener actor from the typed side instead, for example as a child to your user guardian. Then toClassic the typed ActorRef[T] to get an and register that with the classic eventstream instead.

Ah… Yeah, didn’t realize that the same import that brings toClassic to the ActorSystem[T] also adds it for ActorRef[T]. That worked perfectly and I’m capturing DeadLetter in a typed actor to boot.