I was playing with akka remoting and created a small Scala application which sends messages to other Scala apps. That was fine, the receiver application managed to receive the messages, however I got strange serialization warning (like below). I tried to configure serialization following the documentation of akka.io remoting, but didn't manage to find a setup which get rid of those warnings.
I though that I did something wrong and cloned akka/akka github repo, I sbt run akka-samples/akka-sample-remote-scala. I surprised that they have the same errors.
[WARN] [03/29/2016 16:53:40.137] [LookupSystem-akka.remote.default-remote-dispatcher-8] [akka.serialization.Serialization(akka://LookupSystem)] Using the default Java serializer for class [sample.remote.calculator.Subtract] which is not recommended because of performance implications. Use another serializer or disable this warning using the setting 'akka.actor.warn-about-java-serializer-usage'
Anyone can point me the right direction? Thanks.
Well, it's not an error, it's just a warning. Akka uses the Java serialization for user messages so people get started quickly, without having to define any mappings or the like. But you don't want to use it in production, as it's pretty slow. So if you're just playing around, you can ignore the warning (or even disable it in the config as the message explains). For serious business, use JSON, Avro, Kryo, Protobuf...
Define your own serializer in the config
akka {
actor {
serializers {
java = "akka.serialization.JavaSerializer"
proto = "akka.remote.serialization.ProtobufSerializer"
myown = "docs.serialization.MyOwnSerializer"
}
serialization-bindings {
"java.lang.String" = java
"docs.serialization.Customer" = java
"com.google.protobuf.Message" = proto
"docs.serialization.MyOwnSerializable" = myown
"java.lang.Boolean" = myown
}
}
}
You only need to specify the name of an interface or abstract base class of the messages. In case of ambiguity, i.e. the message implements several of the configured classes, the most specific configured class will be used, i.e. the one of which all other candidates are superclasses.
This was taken from http://doc.akka.io/docs/akka/2.4.2/scala/serialization.html#serialization-scala
The topic is also covered in the awesome "Zen of Akka" presentation, chapter 7.
I think lutzh's answer is quite complete. I can only add that if you want to disable this warning you should set following configuration setting:
akka {
actor {
warn-about-java-serializer-usage = false
}
}
Using Java serialization is fine if you are only testing, playing around or don't care about performance for any reason.
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