akka-remote serializable warning

后端 未结 2 468
不知归路
不知归路 2021-02-09 22:42

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 m

2条回答
  •  有刺的猬
    2021-02-09 23:32

    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.

提交回复
热议问题