使用错误的序列化程序与Akka Remoting的Scala protobuffer消息

时间:2016-04-18 06:58:40

标签: scala serialization akka protocol-buffers akka-remote-actor

我一直在努力让Scala Protobuf消息与Akka protobuf序列化器配合使用,但是当我通过远程处理发送消息时,我不断收到此消息

Using the default Java serializer for class [au.com.bluereef.sonar.gui.protocol.auth.AuthenticationResponse] 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'

在应用程序配置中,我有这个设置

akka {
  log-dead-letters = off 
  log-dead-letters-during-shutdown = off 

  actor {
    provider = "akka.remote.RemoteActorRefProvider"

    serializers {
      java = "akka.serialization.JavaSerializer"
      proto = "akka.remote.serialization.ProtobufSerializer"
    }   

    serialization-bindings {
      "java.lang.String" = java
      "com.google.protobuf.Message" = proto
    }   
  }

  remote {
    enabled-transports = ["akka.remote.netty.tcp"]

    netty.tcp {
      hostname = "127.0.0.1"
      port = 8123
    }   
  }
}

消息在src/main/protobuf下的proto文件的单独项目中编译,并使用sbt和ScalaPB("com.trueaccord.scalapb" % "sbt-scalapb" % "0.4.20")插件进行编译。

import com.trueaccord.scalapb.{ScalaPbPlugin => PB} 

name := "protocol"

version := Process("git describe --tags --abbrev=5", baseDirectory.value).!!.replace("\n", "") 

organization := "au.com.bluereef.sonar.gui"

scalaVersion := "2.11.7"

libraryDependencies ++= Seq(
        "com.typesafe.slick" %% "slick" % "3.1.1",
        "org.postgresql" %  "postgresql" % "9.4.1208"
)

PB.protobufSettings

PB.javaConversions in PB.protobufConfig := true

PB.runProtoc in PB.protobufConfig := (args =>
  com.github.os72.protocjar.Protoc.runProtoc("-v300" +: args.toArray))

任何线索?

1 个答案:

答案 0 :(得分:1)

使用scalapb生成的消息不会扩展com.google.protobuf.Message,请尝试使用com.trueaccord.scalapb.GeneratedMessage