gpt4 book ai didi

java - akka.persistence.typed.internal.JournalFailureException : Exception during recovery. 如何解决?

转载 作者:行者123 更新时间:2023-12-01 17:53:19 24 4
gpt4 key购买 nike

使用 Akka 持久性我得到这个异常:

Caused by: akka.persistence.typed.internal.JournalFailureException: Exception during recovery. Last known sequence number [0]. PersistenceId [PersistenceExample], due to: Cannot construct instance of com.exercisePersistence.simpleExample.MyPersistentBehavior$Added (although at least one Creator exists): cannot deserialize from Object value (no delegate- or property-based Creator) at [Source: (byte[])"{"data":"data1"}"; line: 1, column: 2] at akka.persistence.typed.internal.ReplayingEvents.onRecoveryFailure(ReplayingEvents.scala:221) at akka.persistence.typed.internal.ReplayingEvents.onJournalResponse(ReplayingEvents.scala:143) ... 26 common frames omitted

Caused by: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of com.exercisePersistence.simpleExample.MyPersistentBehavior$Added (although at least one Creator exists): cannot deserialize from Object value (no delegate- or property-based Creator) at [Source: (byte[])"{"data":"data1"}"; line: 1, column: 2]

添加的给我异常(exception)的类是:

public class MyPersistentBehavior 
extends EventSourcedBehavior<MyPersistentBehavior.Command,
MyPersistentBehavior.Event, MyPersistentBehavior.State> {

// COMMAND
interface Command {}
public static class Add implements Command {
public final String data;

public Add(String data) {
this.data = data;
}
}
...
}

文件引用.conf

akka {
actor {
serializers {
jackson-json = "akka.serialization.jackson.JacksonJsonSerializer"
jackson-cbor = "akka.serialization.jackson.JacksonCborSerializer"
proto = "akka.remote.serialization.ProtobufSerializer"
}
serialization-bindings {
"com.exercisePersistence.simpleExample.MyPersistentBehavior" = jackson-json
"com.exercisePersistence.simpleExample.MyPersistentBehavior$Added" = jackson-json
#"docs.serialization.CborSerializable" = jackson-cbor
"com.google.protobuf.Message" = proto
}

}

akka.serialization.jackson {
jackson-json-message {
serialization-features {
WRITE_DATES_AS_TIMESTAMPS = on
}
}
jackson-json-event {
serialization-features {
WRITE_DATES_AS_TIMESTAMPS = off
}
}
}
persistence {
journal {
plugin = "leveldb"

leveldb {
dir = "target/persistence/journal"
}
}

snapshot-store.local.dir = "target/persistence/snapshots"
}
}

leveldb {
dir = "target/persistence/journal"
checksum: "off"
class: "akka.persistence.journal.leveldb.LeveldbJournal"
dir: "target/persistence/journal"
fsync: "on"
native: "on"
plugin-dispatcher : "akka.persistence.dispatchers.default-plugin-dispatcher"
replay-dispatcher : "akka.persistence.dispatchers.default-replay-dispatcher"
}

如果想克隆项目,这是 Github 链接:https://github.com/Mazzotta13/AkkaTutorial.git

最佳答案

您有几个不同的选择:

  1. 由于您使用 Jackson 进行序列化,因此您可以向协议(protocol)对象中的构造函数添加 @JsonCreator 注释。
  2. 您可以使用 Lombak 创建协议(protocol)对象,这样可以节省大量 Java 样板,并使用 @NoArgsConstructor 对其进行注释。
  3. 创建一个空的构造函数。

有关它的一些信息可以在这里找到,https://doc.akka.io/docs/akka/current/serialization-jackson.html#annotations

关于java - akka.persistence.typed.internal.JournalFailureException : Exception during recovery. 如何解决?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60760483/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com