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
Assuming you have a service defined using protocol buffers, like this or that
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"
)
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
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.
- ScalaPB for entities generation (only, grpc is not needed)
- Supports streaming
- Supports Monix (grpc4s-monix): Tasks and Observables will be used
- Supports Zio (grpc4s-zio): IO and Stream will be used
- Can be used with zero external libraries (grpc4s-vanilla): Scala Futures will be used with no streaming support