Updates the references to the moved java source files.
- Also specifies the what type of source is being rendered in the syntax-highlighted sections
This commit is contained in:
parent
aa7afd63a8
commit
c509d35455
|
|
@ -15,18 +15,17 @@ The gRPC Java Stub classes are created using a gRPC Java plugin, but first the
|
||||||
plugin must be built and installed.
|
plugin must be built and installed.
|
||||||
|
|
||||||
To build the plugin:
|
To build the plugin:
|
||||||
```
|
```sh
|
||||||
$ pushd external/grpc_java
|
$ pushd external/grpc_java
|
||||||
$ make java_plugin
|
$ make java_plugin
|
||||||
$ popd
|
$ popd
|
||||||
```
|
```
|
||||||
|
|
||||||
To use it to generate the code:
|
To use it to generate the code:
|
||||||
```
|
```sh
|
||||||
$ mkdir -p src/main/java
|
|
||||||
$ protoc -I . helloworld.proto --plugin=protoc-gen-grpc=external/grpc_java/bins/opt/java_plugin \
|
$ protoc -I . helloworld.proto --plugin=protoc-gen-grpc=external/grpc_java/bins/opt/java_plugin \
|
||||||
--grpc_out=src/main/java \
|
--grpc_out=java/src/main/java \
|
||||||
--java_out=src/main/java
|
--java_out=java/src/main/java
|
||||||
```
|
```
|
||||||
|
|
||||||
Next, in [Step - 2](Step_2.md), we'll use the generated Stub implementation to
|
Next, in [Step - 2](Step_2.md), we'll use the generated Stub implementation to
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
# Step-2: Write a service client.
|
# Step-2: Write a service client.
|
||||||
|
|
||||||
This step uses the generated code to write a simple client to access the hello
|
This step uses the generated code to write a simple client to access the hello
|
||||||
service. The full client is in [GreetingsClient.java](src/main/java/ex/grpc/GreetingsClient.java).
|
service. The full client is in [GreetingsClient.java](java/src/main/java/ex/grpc/GreetingsClient.java).
|
||||||
|
|
||||||
|
|
||||||
## Configuring the service to connect to.
|
## Configuring the service to connect to.
|
||||||
|
|
|
||||||
23
Step_3.md
23
Step_3.md
|
|
@ -3,17 +3,17 @@
|
||||||
This step extends the generated server skeleton code to write a simple server
|
This step extends the generated server skeleton code to write a simple server
|
||||||
that provides the hello service. This introduces two new classes:
|
that provides the hello service. This introduces two new classes:
|
||||||
|
|
||||||
- a service implementation [GreetingsImpl.java](src/main/java/ex/grpc/GreetingsImpl.java).
|
- a service implementation [GreetingsImpl.java](java/src/main/java/ex/grpc/GreetingsImpl.java).
|
||||||
|
|
||||||
- a server that hosts the service implementation and allows access over the network: [GreetingsServer.java](src/main/java/ex/grpc/GreetingsServer.java).
|
- a server that hosts the service implementation and allows access over the network: [GreetingsServer.java](java/src/main/java/ex/grpc/GreetingsServer.java).
|
||||||
|
|
||||||
## Service implementation
|
## Service implementation
|
||||||
|
|
||||||
[GreetingsImpl.java](src/main/java/ex/grpc/GreetingsImpl.java)
|
[GreetingsImpl.java](java/src/main/java/ex/grpc/GreetingsImpl.java)
|
||||||
implements the behaviour we require of our GreetingService. There are a
|
implements the behaviour we require of our GreetingService. There are a
|
||||||
number of important features of gRPC being used here:
|
number of important features of gRPC being used here:
|
||||||
|
|
||||||
```
|
```java
|
||||||
public void hello(Helloworld.HelloRequest req,
|
public void hello(Helloworld.HelloRequest req,
|
||||||
StreamObserver<Helloworld.HelloReply> responseObserver) {
|
StreamObserver<Helloworld.HelloReply> responseObserver) {
|
||||||
Helloworld.HelloReply reply = Helloworld.HelloReply.newBuilder().setMessage(
|
Helloworld.HelloReply reply = Helloworld.HelloReply.newBuilder().setMessage(
|
||||||
|
|
@ -24,7 +24,7 @@ number of important features of gRPC being used here:
|
||||||
```
|
```
|
||||||
|
|
||||||
- it provides a class `GreetingsImpl` that implements a generated interface `GreetingsGrpc.Greetings`
|
- it provides a class `GreetingsImpl` that implements a generated interface `GreetingsGrpc.Greetings`
|
||||||
- `GreetingsGrpc.Greetings` declares the method `hello` that was declared in the proto [IDL](src/main/proto/helloworld.proto)
|
- `GreetingsGrpc.Greetings` declares the method `hello` that was declared in the proto [IDL](java/src/main/proto/helloworld.proto)
|
||||||
- `hello's` signature is typesafe:
|
- `hello's` signature is typesafe:
|
||||||
hello(Helloworld.HelloRequest req, StreamObserver<Helloworld.HelloReply> responseObserver)
|
hello(Helloworld.HelloRequest req, StreamObserver<Helloworld.HelloReply> responseObserver)
|
||||||
- `hello` takes two parameters:
|
- `hello` takes two parameters:
|
||||||
|
|
@ -38,11 +38,11 @@ number of important features of gRPC being used here:
|
||||||
|
|
||||||
## Server implementation
|
## Server implementation
|
||||||
|
|
||||||
[GreetingsServer.java](src/main/java/ex/grpc/GreetingsServer.java) shows the
|
[GreetingsServer.java](java/src/main/java/ex/grpc/GreetingsServer.java) shows the
|
||||||
other main feature required to provde the gRPC service; how to allow a service
|
other main feature required to provde the gRPC service; how to allow a service
|
||||||
implementation to be accessed from the network.
|
implementation to be accessed from the network.
|
||||||
|
|
||||||
```
|
```java
|
||||||
private void start() throws Exception {
|
private void start() throws Exception {
|
||||||
server = NettyServerBuilder.forPort(port)
|
server = NettyServerBuilder.forPort(port)
|
||||||
.addService(GreetingsGrpc.bindService(new GreetingsImpl()))
|
.addService(GreetingsGrpc.bindService(new GreetingsImpl()))
|
||||||
|
|
@ -62,7 +62,8 @@ implementation to be accessed from the network.
|
||||||
This is the same as before: our client and server are part of the same maven
|
This is the same as before: our client and server are part of the same maven
|
||||||
package so the same command builds both.
|
package so the same command builds both.
|
||||||
|
|
||||||
```
|
```sh
|
||||||
|
$ cd java
|
||||||
$ mvn package
|
$ mvn package
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
@ -71,12 +72,12 @@ $ mvn package
|
||||||
We've added simple shell scripts to simplifying running the examples. Now
|
We've added simple shell scripts to simplifying running the examples. Now
|
||||||
that they are built, you can run the server with:
|
that they are built, you can run the server with:
|
||||||
|
|
||||||
```
|
```sh
|
||||||
$ ./run_greetings_server.sh
|
$ ./run_greetings_server.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
and in another terminal window confirm that it receives a message.
|
and in another terminal window confirm that it receives a message.
|
||||||
|
|
||||||
```
|
```sh
|
||||||
$ ./run_greetings_client.sh
|
$ ./java/run_greetings_client.sh
|
||||||
```
|
```
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue