Skip to content

vipo/grpc4s

Repository files navigation

grpc4s

Your grpc service is a function.

Main goals of this project:

  • Generate (quite generic) code once and use it with easily plugable backends, i.e. Monix, Zio,...
  • Minimum dependencies

Usage

Assuming you have a service defined using protocol buffers, like this or that

Enable ScalaPB and grpc4s plugins

Put this into project/plugins:

addSbtPlugin("com.thesamet" % "sbt-protoc" % "0.99.19")

resolvers += Resolver.bintrayRepo("vipo", "grpc4s")

libraryDependencies ++= Seq(
  "com.thesamet.scalapb" %% "compilerplugin"   % "0.8.2",
  "com.github.vipo"      %% "grpc4s-generator" % "0.2"
)

Run plugins

Add to your build.sbt:

PB.targets in Compile := Seq(
  scalapb.gen(grpc = false) -> (sourceManaged in Compile).value,
  com.github.vipo.Grpc4sAlgebraGenerator -> (sourceManaged in Compile).value
)

Note: grpc feature of ScalaPB is not needed

Implement your service

Like here or there.

Run

For example with Monix (grpc4s-monix is needed):

val builder = ServerBuilder.forPort(4444)
builder.addService(Monix.build(calculatorFunction, CalculatorAlgebra.definition))
builder.addService(Monix.build(streamingFunction, StreamingAlgebra.definition))
builder.build().start()

Note: CalculatorAlgebra is a generated code.

Features

  1. ScalaPB for entities generation (only, grpc is not needed)
  2. Supports streaming
  3. Supports Monix (grpc4s-monix): Tasks and Observables will be used
  4. Supports Zio (grpc4s-zio): IO and Stream will be used
  5. Can be used with zero external libraries (grpc4s-vanilla): Scala Futures will be used with no streaming support

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages