grpc-java-sbt
Runs a basic gRPC hello-world
Java example ported from Google's repository using SBT build tool, instead of Gradle or Maven (the ones Google's official repository gives support), leveraged on sbt-protobuf
plugin.
More infomation
Please refer to the following links for more information:
- gRPC protocol at www.grpc.io and its java tutorial];
- gRPC Java's and its plugin at grpc/grpc-java`;
- Google's Protocol Buffers at google/protobuf;
- SBT
protobuf
plugin at sbt-protobuf.
Requirements
grpc-java
plugin built. I recommend you to build it from source (downloading from Maven Central is also a possibility if compatible with your OS). You can find build instructions at the grpc-java;protobuf
compiler available (version3.0.0
or up). You can find more information at google/protobuf;sbt
to build the project
Check the repo's Dockerfile for some hints on how to setup your system. More info on the Docker image below.
Settings
Update build.sbt
replacing the following values:
PATH_PROTOC
with the path for yourprotoc
bin;PATH_GRPC_JAVA_PLUGIN
with the path for theprotoc-gen-grpc-java
gRPC Java's protobuf plugin.
Run
In one terminal run sbt run
and select the hello-world-server
main to spawn a server. In another terminal run sbt run
again and select hello-world-client
main to spawn a client (you can spawn multiple clients by repeating this step).
That's it!
Docker
I'm also providing a Dockerfile that builds an image that pre-builds all the listed requirements, and runs the example.
- To build the image just run:
docker build --rm -t jfloff/grpc-java-sbt .
- Run the image with:
docker run -it --name grpc-java-sbt jfloff/grpc-java-sbt
- And for a 2nd terminal run:
docker exec -ti grpc-java-sbt run sbt