Scala Akka and Protocol Buffers

I play Akka doing deletion and serialization and I want to understand a few things to get started. I read the serialization documentation here:

http://doc.akka.io/docs/akka/2.3.4/scala/serialization.html

According to the documentation, it seems that this is enough to just provide these things in my application.conf application, under:

akka.actor { serializers { java = "akka.serialization.JavaSerializer" proto = "akka.remote.serialization.ProtobufSerializer" } serialization-bindings { "com.mycompany.messages.MyMessage" = proto } } 

And suppose I have a case class in this package, for example:

 package com.mycompany.messages; case class MyMessage(name: String, year: Int) 

And then in my actors I can just do something like this:

 class ClientActor extends Actor { def receive = { case x: MyMessage => ... } } 

Will this configuration be sufficient or will I need to do something else? I looked at the external serializer mentioned in the documentation: https://github.com/romix/akka-protostuff-serialization

It looks very promising, but I was looking for something standard that comes out of the box from Akka.

I am also studying message version compatibility testing. Say Actor A is talking to Actor B with MessageX

MessageX may initially contain the following fields:

 a: String, b: String, c: String 

Now let's say that Actor B updates its version of Message X , lets call it Message X +1

Message X +1 now includes another field, for example:

 a: String, b: String, c: String, d: String 

But Actor is still sending an older version of the message, just Message X ... will Actor B still know how to deserialize the old message?

Thanks for the help.

+6
source share
2 answers

The Protobuf serializer can only serialize Protobuf messages. Therefore, in order for things to work the way you want, you must make a protobuf message to MyMessage.

+4
source

Just additional information about your version issues;

Protobuf can serialize / deserialize different versions of the same message types. You must maintain the indexes of existing fields and add additional new ones accordingly to your file duct descriptor.

+3
source

Source: https://habr.com/ru/post/971640/


All Articles