Search code examples
scalaserializationakkaprotocol-buffersakka-remote-actor

Scala protobuffer messages using wrong serializer with Akka Remoting


I have been trying to get Scala Protobuf messages working with the Akka protobuf serializer but I keep getting this response when I send the messages via remoting

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'

In the application config I have this setup

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
    }   
  }
}

The messages are compiled in a separate project with the proto files under src/main/protobuf and are compiled with sbt and the ScalaPB ("com.trueaccord.scalapb" % "sbt-scalapb" % "0.4.20") plugin.

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))

Any clues?


Solution

  • Messages generated with scalapb don't extend com.google.protobuf.Message, try using com.trueaccord.scalapb.GeneratedMessage instead.