我想知道是否有可能知道何时传递邮件。因为我想稍后关闭actorsystem。下面的代码连接到远程参与者,然后发送一条消息。但是在某些情况下,本地参与者系统似乎关闭得太早了。

ActorSystem system = ActorSystem.create("Test", config.getConfig("webbackend"));
ActorSelection communicator = system.actorSelection("akka.tcp://[email protected]:2555/user/Communicator");
communicator.tell(new TimerTransmissionCmd(channel.getId()), ActorRef.noSender());
//system.shutdown();

最佳答案

发送消息后,尝试添加以下代码:

Boolean wasProcessed = (Integer)Await.result(Patterns.ask(communicator, new ResultClass(), 5000),
            Duration.create(5000, TimeUnit.MILLISECONDS));

if(wasProcessed){
    actorSystem.shutdown();
}


您还必须在Actor类中添加以下内容:

private boolean wasProcessed = false;

@Override
public void onReceive(Object messageReceived) throws Exception {
    if (messageReceived instanceof ResultClass) {
        this.workerActor1.tell(wasProcessed, getSender());
    } else {
        //Put your process code here
        wasProcessed = true;
    }
}


但是我建议您配置一个谨慎的超时,然后始终关闭系统。

10-04 12:20