Protobuf uses Guava 30.1.1, so I upgrade it at the same time. It also caused an update to rules_jvm_external and reworking the Bazel build. Protobuf no longer requires bind() so they were dropped. Although Protobuf's protobuf_deps() brings in rules_jvm_external, and so we don't need to define it ourselves, it seems better to define it directly and not depend on transitive deps since we use it directly. Protobuf now has support for maven_install() by exposing PROTOBUF_MAVEN_ARTIFACTS, which required reorganizing the WORKSPACE to use maven_install() after loading protobuf. Protobuf still doesn't define target overrides for itself so we still maintain those. When reorganizing the WORKSPACE I noticed http_archive should ideally be above io_grpc_grpc_java as most users will need it there, so I fixed that since there were lots of other load()-reordering already. |
||
|---|---|---|
| .. | ||
| src | ||
| BUILD.bazel | ||
| README.md | ||
| build.gradle | ||
| pom.xml | ||
| settings.gradle | ||
README.md
gRPC Hostname Example
The hostname example is a Hello World server whose response includes its hostname. It also supports health and reflection services. This makes it a good server to test infrastructure, like load balancing.
The example requires grpc-java to already be built. You are strongly encouraged to check out a git release tag, since there will already be a build of grpc available. Otherwise you must follow COMPILING.
Build the example
-
Build the hello-world example client. See the examples README
-
Build this server. From the
grpc-java/examples/examples-hostnamedirectory:
$ ../gradlew installDist
This creates the script build/install/hostname-server/bin/hostname-server that
runs the example.
To run the hostname example, run:
$ ./build/install/hostname/bin/hostname-server
And in a different terminal window run the hello-world client:
$ ../build/install/examples/bin/hello-world-client
Maven
If you prefer to use Maven:
-
Build the hello-world example client. See the examples README
-
Run in this directory:
$ mvn verify
$ # Run the server (from the examples-hostname directory)
$ mvn exec:java -Dexec.mainClass=io.grpc.examples.hostname.HostnameServer
$ # In another terminal run the client (from the examples directory)
$ cd ..
$ mvn exec:java -Dexec.mainClass=io.grpc.examples.helloworld.HelloWorldClient
Bazel
If you prefer to use Bazel, run from the grpc-java/examples directory:
$ bazel build :hello-world-client example-hostname:hostname-server
$ # Run the server
$ ./bazel-bin/example-hostname/hostname-server
$ # In another terminal run the client
$ ./bazel-bin/hello-world-client