Akka 2.6 如何阅读 Akka Typed 中的“Dead Letters”?
Akka 2.6 how to read `Dead Letters` in Akka Typed?
我已阅读此文档 https://doc.akka.io/docs/akka/current/general/message-delivery-reliability.html#dead-letters,其中说:
An actor can subscribe to class akka.actor.DeadLetter on the event stream, see Event Stream for how to do that.
在事件流文档中: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 中,akka.actor.typed.ActorSystem.eventStream()
中没有名为 subscribe()
的方法。
创建类型化 ActorSystem 和处理消息类型 DeadLetter 的类型化 Actor 后,您应该能够订阅 EventStream,如下所示。
import akka.actor.typed.eventstream.EventStream;
system.eventStream().tell(new EventStream.Subscribe(DeadLetter.class, actor));
我已阅读此文档 https://doc.akka.io/docs/akka/current/general/message-delivery-reliability.html#dead-letters,其中说:
An actor can subscribe to class akka.actor.DeadLetter on the event stream, see Event Stream for how to do that.
在事件流文档中: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 中,akka.actor.typed.ActorSystem.eventStream()
中没有名为 subscribe()
的方法。
创建类型化 ActorSystem 和处理消息类型 DeadLetter 的类型化 Actor 后,您应该能够订阅 EventStream,如下所示。
import akka.actor.typed.eventstream.EventStream;
system.eventStream().tell(new EventStream.Subscribe(DeadLetter.class, actor));