mirror of https://github.com/grpc/grpc.io.git
Java QS and Tutorial cleanup (#108)
Mainly just markdown cleanup. Contributes to #87 and #88 for Java.
This commit is contained in:
parent
355070ca21
commit
79ee012593
|
|
@ -21,9 +21,9 @@ clones the entire repository, but you just need the examples for this quickstart
|
||||||
and other tutorials):
|
and other tutorials):
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
$ # Clone the repository at the latest release to get the example code:
|
# Clone the repository at the latest release to get the example code:
|
||||||
$ git clone -b {{< param grpc_java_release_tag >}} https://github.com/grpc/grpc-java
|
$ git clone -b {{< param grpc_java_release_tag >}} https://github.com/grpc/grpc-java
|
||||||
$ # Navigate to the Java examples:
|
# Navigate to the Java examples:
|
||||||
$ cd grpc-java/examples
|
$ cd grpc-java/examples
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
@ -31,19 +31,19 @@ $ cd grpc-java/examples
|
||||||
|
|
||||||
From the `examples` directory:
|
From the `examples` directory:
|
||||||
|
|
||||||
1. Compile the client and server
|
1. Compile the client and server
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
$ ./gradlew installDist
|
$ ./gradlew installDist
|
||||||
```
|
```
|
||||||
|
|
||||||
2. Run the server
|
2. Run the server
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
$ ./build/install/examples/bin/hello-world-server
|
$ ./build/install/examples/bin/hello-world-server
|
||||||
```
|
```
|
||||||
|
|
||||||
3. In another terminal, run the client
|
3. In another terminal, run the client
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
$ ./build/install/examples/bin/hello-world-client
|
$ ./build/install/examples/bin/hello-world-client
|
||||||
|
|
@ -62,7 +62,7 @@ server and the client "stub" have a `SayHello` RPC method that takes a
|
||||||
server, and that this method is defined like this:
|
server, and that this method is defined like this:
|
||||||
|
|
||||||
|
|
||||||
```java
|
```protobuf
|
||||||
// The greeting service definition.
|
// The greeting service definition.
|
||||||
service Greeter {
|
service Greeter {
|
||||||
// Sends a greeting
|
// Sends a greeting
|
||||||
|
|
@ -83,7 +83,7 @@ Let's update this so that the `Greeter` service has two methods. Edit
|
||||||
`src/main/proto/helloworld.proto` and update it with a new `SayHelloAgain`
|
`src/main/proto/helloworld.proto` and update it with a new `SayHelloAgain`
|
||||||
method, with the same request and response types:
|
method, with the same request and response types:
|
||||||
|
|
||||||
```java
|
```protobuf
|
||||||
// The greeting service definition.
|
// The greeting service definition.
|
||||||
service Greeter {
|
service Greeter {
|
||||||
// Sends a greeting
|
// Sends a greeting
|
||||||
|
|
@ -138,7 +138,6 @@ private class GreeterImpl extends GreeterGrpc.GreeterImplBase {
|
||||||
responseObserver.onCompleted();
|
responseObserver.onCompleted();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
...
|
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Update the client
|
#### Update the client
|
||||||
|
|
@ -173,19 +172,19 @@ public void greet(String name) {
|
||||||
|
|
||||||
Just like we did before, from the `examples` directory:
|
Just like we did before, from the `examples` directory:
|
||||||
|
|
||||||
1. Compile the client and server
|
1. Compile the client and server
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
$ ./gradlew installDist
|
$ ./gradlew installDist
|
||||||
```
|
```
|
||||||
|
|
||||||
2. Run the server
|
2. Run the server
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
$ ./build/install/examples/bin/hello-world-server
|
$ ./build/install/examples/bin/hello-world-server
|
||||||
```
|
```
|
||||||
|
|
||||||
3. In another terminal, run the client
|
3. In another terminal, run the client
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
$ ./build/install/examples/bin/hello-world-client
|
$ ./build/install/examples/bin/hello-world-client
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,7 @@ define the gRPC *service* and the method *request* and *response* types using
|
||||||
[protocol
|
[protocol
|
||||||
buffers](https://developers.google.com/protocol-buffers/docs/overview). You can
|
buffers](https://developers.google.com/protocol-buffers/docs/overview). You can
|
||||||
see the complete .proto file in
|
see the complete .proto file in
|
||||||
[`grpc-java/examples/src/main/proto/route_guide.proto`](https://github.com/grpc/grpc-java/blob/master/examples/src/main/proto/route_guide.proto).
|
[grpc-java/examples/src/main/proto/route_guide.proto](https://github.com/grpc/grpc-java/blob/master/examples/src/main/proto/route_guide.proto).
|
||||||
|
|
||||||
As we're generating Java code in this example, we've specified a `java_package`
|
As we're generating Java code in this example, we've specified a `java_package`
|
||||||
file option in our .proto:
|
file option in our .proto:
|
||||||
|
|
@ -167,9 +167,8 @@ a special gRPC Java plugin. You need to use the
|
||||||
both proto2 and proto3 syntax) in order to generate gRPC services.
|
both proto2 and proto3 syntax) in order to generate gRPC services.
|
||||||
|
|
||||||
When using Gradle or Maven, the protoc build plugin can generate the necessary
|
When using Gradle or Maven, the protoc build plugin can generate the necessary
|
||||||
code as part of the build. You can refer to the <a
|
code as part of the build. You can refer to the [grpc-java README][] for
|
||||||
href="https://github.com/grpc/grpc-java/blob/master/README.md">README</a> for
|
how to generate code from your own `.proto` files.
|
||||||
how to generate code from your own .proto files.
|
|
||||||
|
|
||||||
The following classes are generated from our service definition:
|
The following classes are generated from our service definition:
|
||||||
|
|
||||||
|
|
@ -300,6 +299,7 @@ RPC, we use the response observer's `onCompleted()` method to tell gRPC that
|
||||||
we've finished writing responses.
|
we've finished writing responses.
|
||||||
|
|
||||||
##### Client-side streaming RPC
|
##### Client-side streaming RPC
|
||||||
|
|
||||||
Now let's look at something a little more complicated: the client-side streaming
|
Now let's look at something a little more complicated: the client-side streaming
|
||||||
method `RecordRoute`, where we get a stream of `Point`s from the client and
|
method `RecordRoute`, where we get a stream of `Point`s from the client and
|
||||||
return a single `RouteSummary` with information about their trip.
|
return a single `RouteSummary` with information about their trip.
|
||||||
|
|
@ -675,10 +675,10 @@ for our client-streaming method. Although each side will always get the other's
|
||||||
messages in the order they were written, both the client and server can read and
|
messages in the order they were written, both the client and server can read and
|
||||||
write in any order — the streams operate completely independently.
|
write in any order — the streams operate completely independently.
|
||||||
|
|
||||||
|
|
||||||
### Try it out!
|
### Try it out!
|
||||||
|
|
||||||
Follow the instructions in the example directory
|
Follow the instructions in the [example directory README][] to build and run the
|
||||||
[README](https://github.com/grpc/grpc-java/blob/master/examples/README.md) to
|
client and server.
|
||||||
build and run the client and server.
|
|
||||||
|
|
||||||
|
[example directory README]: https://github.com/grpc/grpc-java/blob/master/examples/README.md
|
||||||
|
[grpc-java README]: https://github.com/grpc/grpc-java/blob/master/README.md
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue