我们正在尝试将 protobuf 与 Akka 一起使用,并通过 protobuf 序列化所有 Akka 消息。对于 Scala,我们有一个名为 ScalaPB 的库,它可以帮助我们生成类,其中包括用于序列化或反序列化数据的方法等parseFrom
。toByteArray
但是,当我们尝试运行程序时,出现以下异常:
akka.actor.dungeon.SerializationCheckFailedException: Failed to serialize and deserialize message of type com.knoldus.akkaserialization.msg.example.Bang$ for testing. To avoid this error, either disable 'akka.actor.serialize-messages', mark the message with 'akka.actor.NoSerializationVerificationNeeded', or configure serialization to support this message
application.conf 文件包含以下配置:
akka {
actor {
allow-java-serialization = off
serialize-messages = on
serializers {
proto = "akka.remote.serialization.ProtobufSerializer"
}
serialization-bindings {
"com.knoldus.akkaserialization.msg.example.Bang" = proto
"com.knoldus.akkaserialization.msg.example.Message" = proto
}
}
}
这些类通过 ScalaPB 生成并包含所有需要的方法com.knoldus.akkaserialization.msg.example.Bang
。com.knoldus.akkaserialization.msg.example.Message
akka.remote.serialization.ProtobufSerializer
定义源代码,
This Serializer serializes `akka.protobuf.Message` and `com.google.protobuf.Message` It is using reflection to find the `parseFrom` and `toByteArray` methods to avoid dependency to `com.google.protobuf`
所以,我们期望,这会自动读取我们的案例类Bang
并Message
执行序列化,但不幸的是得到序列化异常。
你能帮忙弄清楚 ScalaPB 和 ProtoBuff 的确切问题吗?