This library enables you to write purely functional gRPC services using ZIO.
- Supports all types of RPCs (unary, client streaming, server streaming, bidirectional).
- Uses ZIO's
Stream
to let you easily implement streaming requests. - Cancellable RPCs: client-side ZIO interruptions are propagated to the server to abort the request and save resources.
Find the latest snapshot in here.
Add the following to your project/plugins.sbt
:
val zioGrpcVersion = "0.4.0"
addSbtPlugin("com.thesamet" % "sbt-protoc" % "0.99.34")
libraryDependencies += "com.thesamet.scalapb.zio-grpc" %% "zio-grpc-codegen" % zioGrpcVersion
Add the following to your build.sbt
:
val grpcVersion = "1.31.1"
PB.targets in Compile := Seq(
scalapb.gen(grpc = true) -> (sourceManaged in Compile).value,
scalapb.zio_grpc.ZioCodeGenerator -> (sourceManaged in Compile).value,
)
libraryDependencies ++= Seq(
"com.thesamet.scalapb" %% "scalapb-runtime-grpc" % scalapb.compiler.Version.scalapbVersion,
"io.grpc" % "grpc-netty" % grpcVersion
)
Place your service proto files in src/main/protobuf
, and the plugin
will generate Scala sources for them. Learn more about how to use ZIO gRPC generated code.
See a full example at the examples directory.