我有一个 java 对象,它不是使用 actorSelection(Path)) 从演员系统中选择演员的演员。系统中可能不存在所选参与者。
在 Java Api 中,ActorSelection 不存在 ask(),因此我无法向 Actor 选择发送和识别消息并使用响应的发送者。
我试图通过演员选择将消息发送给演员然后对死信作出反应来解决问题。但我没有收到任何死信。
如果演员还活着或不存在,我如何检查 ActorSelection?
ActorSystem system = ActorSystem.create("test");
//create test actor
system.actorOf(Props.create(TestActor.class), "testActor");
//add dead letter listener to the system
ActorRef eventBusActor = asys.actorOf(Props.create(EventBusActor.class), "eventbusactor");
system.eventStream().subscribe(eventBusActor, DeadLetter.class);
//This works. The test actor receives the message
ActorSelection a1 = asys.actorSelection("/user/testActor");
a1.tell("hello", ActorRef.noSender());
//This does not work and does not send dead letters
ActorSelection a2 = asys.actorSelection("/user/doesnotexist");
a2.tell("hello", ActorRef.noSender());
//Does not compile, because ask needs an ActorRef as first argument
ActorSelection a3 = asys.actorSelection("/user/test");
Future f = Patterns.ask(a3, new Identify(), 1000);