【发布时间】:2019-08-15 16:01:38
【问题描述】:
我们正在尝试将 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
}
}
}
这些类com.knoldus.akkaserialization.msg.example.Bang 和com.knoldus.akkaserialization.msg.example.Message 通过ScalaPB 生成并包含所有需要的方法。
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 的确切问题吗?
【问题讨论】:
标签: scala serialization akka protocol-buffers scalapb