akka-remote serializable warning

后端 未结 2 470
不知归路
不知归路 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:26

    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.

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题