Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Akka 2.6 how to read `Dead Letters` in Akka Typed?

I have read this doc https://doc.akka.io/docs/akka/current/general/message-delivery-reliability.html#dead-letters, which says:

An actor can subscribe to class akka.actor.DeadLetter on the event stream, see Event Stream for how to do that.

in the Event Stream doc: https://doc.akka.io/docs/akka/current/event-bus.html#event-stream, sample code seems about classic Akka, and package is akka.actor.ActorSystem not akka.actor.typed.ActorSystem:

import akka.actor.ActorRef;
import akka.actor.ActorSystem;

final ActorSystem system = ActorSystem.create("DeadLetters");
final ActorRef actor = system.actorOf(Props.create(DeadLetterActor.class));
system.getEventStream().subscribe(actor, DeadLetter.class);

but in Akka Typed, there is no method named subscribe() inakka.actor.typed.ActorSystem.eventStream().

like image 695
mahengyang Avatar asked Dec 06 '19 06:12

mahengyang


1 Answers

After creating a typed ActorSystem and a typed Actor that handles the message type DeadLetter, you should be able to subscribe to the EventStream like shown below.

import akka.actor.typed.eventstream.EventStream;

system.eventStream().tell(new EventStream.Subscribe(DeadLetter.class, actor));
like image 56
det0 Avatar answered Nov 15 '22 08:11

det0