Eric Anderson | e7d7c5b | 2020-01-17 15:50:49 -0800 | [diff] [blame] | 1 | gRPC Hostname Example |
| 2 | ===================== |
| 3 | |
| 4 | The hostname example is a Hello World server whose response includes its |
| 5 | hostname. It also supports health and reflection services. This makes it a good |
| 6 | server to test infrastructure, like load balancing. |
| 7 | |
| 8 | The example requires grpc-java to already be built. You are strongly encouraged |
| 9 | to check out a git release tag, since there will already be a build of grpc |
| 10 | available. Otherwise you must follow [COMPILING](../../COMPILING.md). |
| 11 | |
| 12 | ### Build the example |
| 13 | |
| 14 | 1. Build the hello-world example client. See [the examples README](../README.md) |
| 15 | |
| 16 | 2. Build this server. From the `grpc-java/examples/examples-hostname` directory: |
| 17 | ``` |
| 18 | $ ../gradlew installDist |
| 19 | ``` |
| 20 | |
| 21 | This creates the script `build/install/hostname-server/bin/hostname-server` that |
| 22 | runs the example. |
| 23 | |
| 24 | To run the hostname example, run: |
| 25 | |
| 26 | ``` |
Eric Anderson | e38d928 | 2023-05-15 15:17:04 -0700 | [diff] [blame] | 27 | $ ./build/install/hostname-server/bin/hostname-server |
Eric Anderson | e7d7c5b | 2020-01-17 15:50:49 -0800 | [diff] [blame] | 28 | ``` |
| 29 | |
| 30 | And in a different terminal window run the hello-world client: |
| 31 | |
| 32 | ``` |
| 33 | $ ../build/install/examples/bin/hello-world-client |
| 34 | ``` |
| 35 | |
| 36 | ### Maven |
| 37 | |
| 38 | If you prefer to use Maven: |
| 39 | 1. Build the hello-world example client. See [the examples README](../README.md) |
| 40 | |
| 41 | 2. Run in this directory: |
| 42 | ``` |
| 43 | $ mvn verify |
| 44 | $ # Run the server (from the examples-hostname directory) |
| 45 | $ mvn exec:java -Dexec.mainClass=io.grpc.examples.hostname.HostnameServer |
| 46 | $ # In another terminal run the client (from the examples directory) |
| 47 | $ cd .. |
| 48 | $ mvn exec:java -Dexec.mainClass=io.grpc.examples.helloworld.HelloWorldClient |
| 49 | ``` |
| 50 | |
| 51 | ### Bazel |
| 52 | |
| 53 | If you prefer to use Bazel, run from the `grpc-java/examples` directory: |
| 54 | ``` |
| 55 | $ bazel build :hello-world-client example-hostname:hostname-server |
| 56 | $ # Run the server |
| 57 | $ ./bazel-bin/example-hostname/hostname-server |
| 58 | $ # In another terminal run the client |
| 59 | $ ./bazel-bin/hello-world-client |
| 60 | ``` |