I'm playing around with Akka's remoting and serialization facilities and want to understand a few things to get started. I've read over the documentation on serialization here:
http://doc.akka.io/docs/akka/2.3.4/scala/serialization.html
According to the documentation, it seems that it would be enough to just supply these things in my application.conf, under:
akka.actor {
serializers {
java = "akka.serialization.JavaSerializer"
proto = "akka.remote.serialization.ProtobufSerializer"
}
serialization-bindings {
"com.mycompany.messages.MyMessage" = proto
}
}
And let's assume I have a case class under that package, such as:
package com.mycompany.messages;
case class MyMessage(name: String, year: Int)
And then in my actors, I can simly do something like this:
class ClientActor extends Actor {
def receive = {
case x: MyMessage => ...
}
}
Would this configuration be enough, or would I need to do something more? I've looked at an external serializer mentioned from the documentation here: https://github.com/romix/akka-protostuff-serialization
This looks really promising, but I was looking for something standard that comes out of the box from Akka.
I'm also looking into testing for message version compatibility. Let's say Actor A talks to Actor B with MessageX
MessageX initially might contain fields like this:
a: String, b: String, c: String
Now let's say Actor B upgrades its version of Message X, lets call it Message X +1
Message X +1 now includes another field, like so:
a: String, b: String, c: String, d: String
But Actor A is still sending the older version of the message, just simply Message X... would Actor B still know how to deserialize the old message?
Thanks for the help.
The Protobuf serializer can only serialize Protobuf messages. So for things to work as you want you need to make MyMessage a protobuf message.
Just an additional information on your versioning concerns;
Protobuf can serialise/ deserialize different versions of the same message types. You have to sustain the already present fields' indexes and add the additional new ones accordingly, in your proto file descriptor.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With