我已阅读此文档https://doc.akka.io/docs/akka/current/general/message-delivery-reliability.html#dead-letters,其中说:
演员可以订阅事件流上的akka.actor.DeadLetter类,有关如何操作,请参阅事件流。
在事件流文档中:https://doc.akka.io/docs/akka/current/event-bus.html#event-stream,示例代码似乎与经典Akka有关,而程序包是akka.actor.ActorSystem
而不是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);
但是在Akka Typed中,subscribe()
中没有名为akka.actor.typed.ActorSystem.eventStream()
的方法。
创建类型化的ActorSystem和处理消息类型DeadLetter的类型化的Actor之后,您应该能够订阅EventStream,如下所示。
import akka.actor.typed.eventstream.EventStream;
system.eventStream().tell(new EventStream.Subscribe(DeadLetter.class, actor));