we are trying to using protobuf with Akka and serialize all Akka messages via protobuf. For Scala, we have a library called ScalaPB which help us to generate the class, which includes methods like parseFrom
, toByteArray
etc for serializing or deserialize our data. But, while we try to run the program, getting below exception:
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 file contains below configuration:
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
}
}
}
These classes com.knoldus.akkaserialization.msg.example.Bang
and com.knoldus.akkaserialization.msg.example.Message
generates via ScalaPB and contains all require methods.
Source code of akka.remote.serialization.ProtobufSerializer
define,
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`
So, we expecting, this automatically reads our case classes Bang
and Message
and perform serialization, but unfortunately getting serialization exception.
Could you help to figure out what exact problem with ScalaPB and ProtoBuff?