akka.pattern.asktimeoutexception

lrl1mhuk  于 2021-06-10  发布在  Cassandra
关注(0)|答案(1)|浏览(539)

我刚从lagom&akka开始。我遵循的设计描述领域建模与akka持久性类型
我正在尝试创建一个实体的全新示例( EntityState ). 但是事件没有得到持久化,我得到以下错误:

00:54:27.862 [error] com.example.impl.entity.EntityClass [persistencePhase=running-cmd, akkaAddress=akka://XXX@127.0.0.1:60685, akkaSource=akka://XXX/system/sharding/StateClass/186/ID1, sourceActorSystem=XXX, persistenceId=StateClass|ID1] - Supervisor StopSupervisor saw failure: null
java.lang.NullPointerException: null
    at akka.persistence.typed.javadsl.EventSourcedBehavior.$anonfun$apply$4(EventSourcedBehavior.scala:195)
    at akka.persistence.typed.internal.Running$RunningState.applyEvent(Running.scala:78)
    at akka.persistence.typed.internal.Running$HandlingCommands.applyEffects(Running.scala:153)
    at akka.persistence.typed.internal.Running$HandlingCommands.onCommand(Running.scala:123)
    at akka.persistence.typed.internal.Running$HandlingCommands.onMessage(Running.scala:105)
    at akka.persistence.typed.internal.Running$HandlingCommands.onMessage(Running.scala:100)
    at akka.actor.typed.scaladsl.AbstractBehavior.receive(AbstractBehavior.scala:83)

我有一个create命令 onCreate() ,并最终尝试持久化entitycreated事件。
服务实现方法

@Override
public ServiceCall<CreateMessage, StateView> createState(){
    return message ->
            entityRef(message.getName())
                    .<EntityClass.Accepted>ask(replyTo -> new EntityClass.Create(message, replyTo), askTimeout)
                    .thenApply(accepted -> toStateView(accepted.getSummary()));
}

命令处理程序:

private ReplyEffect<Event, StateClass> onCreate(StateClass state, Create cmd) {
    return Effect()
            .persist(new EntityCreated(cmd.getDetails().getName(), Instant.now()))
            .thenReply(cmd.replyTo, e -> new Accepted(EntityClass.toSummary(e)));
}

我能够确认以下内容:
过程中引发异常 persist() Cassandra没有这项活动
谢谢你的帮助。提前谢谢!

zi8p0yeb

zi8p0yeb1#

出现异常的真正原因似乎是因为我应该添加处理事件的逻辑,如下所示: helloEvents() ,我需要添加类似以下的逻辑:

if (eventAndOffset.first() instanceof HelloEvent.GreetingMessageChanged) {
    HelloEvent.GreetingMessageChanged messageChanged = (HelloEvent.GreetingMessageChanged) eventAndOffset.first();
    eventToPublish = new GreetingMessageChanged(messageChanged.getName(), messageChanged.getMessage());
}

此外,在总的 eventHandler() ,我需要添加类似以下的逻辑:

builder.forAnyState()
    .onEvent(GreetingMessageChanged.class, (state, evt) ->
        // We simply update the current state to use the greeting message from
        // the event.
        state.withMessage(evt.message)
);

相关问题