我有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())
        }
}


因此,您可以看到已经向每个子参与者发送了两条消息。但不幸的是,我只收到一条消息,并且还收到有关INFODeadLetter通知。 Message was not delivered. [1] dead letters encountered.

您能否帮助我找到为什么我没有收到第二条消息?这与关闭actor有关,但我只能在Subactors的最低位置停止它。

谢谢你的帮助!

最佳答案

看来您实际上并没有从A或B都将MessageResponseX返回到主要对象:您正在发送MessageResponseX.events + Long。但是,根据+运算符可以处理您的事件,您可能发送的是Long,String或Long / Object的集合。

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

08-24 18:49