Lagom gRPC support overview

gRPC

gRPC is a transport mechanism for request/response and (non-persistent) streaming use cases. See Akka gRPC documentation for an explanation of why gRPC and when to use it as your transport.

How to add the sbt plugin

To get started, for both client and server code generation, you will need to add Akka gRPC sbt plugin:

sbt
// in project/plugins.sbt:
addSbtPlugin("com.lightbend.akka.grpc" % "sbt-akka-grpc" % "0.6.0")

And then in your build.sbt file, you will need to enable the plugin for the project that contains the .proto files, and configure the language used in project:

Scala
// in build.sbt:
lazy val `greeter-service-impl` = (project in file("greeter-impl"))
    .enablePlugins(LagomScala)
    .enablePlugins(AkkaGrpcPlugin)
    // enables serving HTTP/2
    .enablePlugins(PlayAkkaHttp2Support)
    .settings(
        // Using Scala
        akkaGrpcGeneratedLanguages := Seq(AkkaGrpc.Scala),
        akkaGrpcGeneratedSources := Seq( AkkaGrpc.Server, AkkaGrpc.Client ),
        akkaGrpcExtraGenerators in Compile += PlayScalaServerCodeGenerator
    )
Java
// in build.sbt:
lazy val `greeter-service-impl` = (project in file("greeter-impl"))
    .enablePlugins(LagomScala)
    .enablePlugins(AkkaGrpcPlugin)
    // enables serving HTTP/2
    .enablePlugins(PlayAkkaHttp2Support)
    .settings(
        // Using Java
        akkaGrpcGeneratedLanguages := Seq(AkkaGrpc.Java),
        akkaGrpcGeneratedSources := Seq( AkkaGrpc.Server, AkkaGrpc.Client ),
        akkaGrpcExtraGenerators in Compile += PlayScalaServerCodeGenerator
    )

After that, you should be able to generate and use the code to serve or consume gRPC services.

Found an error in this documentation? The source code for this page can be found here. Please feel free to edit and contribute a pull request.