遇到阿卡死信

时间:2015-04-08 13:11:16

标签: java akka

我有MainActor内部构造函数初始化两个子SubActorASubActorB

SubActorA= this.getContext().actorOf(Props.create(SubActorA.class), "SubActorA");
SubActorB= this.getContext().actorOf(Props.create(SubActorB.class), "SubActorB");

public class SubActorA extends UntypedActor {

    @Override
    public void onReceive(Object o) throws Exception {
        Thread.sleep(3000);
        getSender().tell(new MessageResponseA().events + System.currentTimeMillis(), getSelf());
        getContext().stop(getSelf());
    }
}

public class SubActorB extends UntypedActor {

    @Override
    public void onReceive(Object o) throws Exception {
        Thread.sleep(3000);
        getSender().tell(new MessageResponseB().events + System.currentTimeMillis(), getSelf());
        getContext().stop(getSelf());
    }
}

MainActor收到来自外部演员世界的Message请求:

public Future<Iterable<Object>> start(){

    final ArrayList<Future<Object>> futures = new ArrayList<>();
    Timeout t = new Timeout(100, TimeUnit.MILLISECONDS);
    futures.add(ask(this.mainActor, new Message(customerCookie), t));
    final Future<Iterable<Object>> aggregate = Futures.sequence(futures,
            system.dispatcher());

    return aggregate;
}

MainActor收到Message后,会立即将其发送给其子女SubActorASubActorB

    @Override
    public void onReceive(Object message) throws Exception {
        if(message instanceof `Message`){
            generalPersonalisationSender = getSender();
            SubActorA.tell(new MessageA(customerCookie), getSelf());
            SubActorB.tell(new MessageB(customerCookie), getSelf());
        }
        else if(message instanceof `MessageResponseA`){
            listener.tell(message, getSelf())
        }
        else if(message instanceof `MessageResponseB`){
            listener.tell(message, getSelf())
        }
}

因此,您可以看到已向每个子actor发送了两条消息。但遗憾的是,我只收到了一条消息,并且INFO通知了DeadLetterMessage was not delivered. [1] dead letters encountered.

你能帮我找一下为什么我没有收到第二条消息吗?这是关闭一个演员,但我只在最低Subactors内停止。

感谢您的帮助!

1 个答案:

答案 0 :(得分:2)

您似乎实际上没有从A或B返回MessageResponseX到主要的:您正在发送MessageResponseX.events + Long。然而,根据+运算符处理事件,您可能发送Long,String或Long / Object集合。

因此,您的MainActor接收方法不会拦截它,它会转到DeadLetters。