Wild Goat
Wild Goat

Reputation: 3579

Akka dead letters encountered

I have MainActor which inside constructor initializes two child SubActorA and SubActorB.

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 receives a Message request from outside actors world:

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;
}

As soon as MainActor received Message it sends it to two its childs SubActorA and SubActorB.

    @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())
        }
}

So you can see that two messages has been sent to each of sub actors. But unfortunately I am getting only one message back and aslo INFO notification about DeadLetter. Message was not delivered. [1] dead letters encountered.

Could you please help me to find why i am not getting 2nd message? is it something to do with shutting down an actor, but I stop it only on lowest inside Subactors.

Thanks for any help!

Upvotes: 1

Views: 2268

Answers (1)

Diego Martinoia
Diego Martinoia

Reputation: 4652

It seems that you are not actually returning a MessageResponseX from neither A or B to the main one: you are sending a MessageResponseX.events+Long . According to however the + operator works on your events, you are probably sending either a Long, a String or a collection of Long/Object.

Therefore, your MainActor receive method is not intercepting it, and it goes to DeadLetters.

Upvotes: 2

Related Questions