Skip to content
Snippets Groups Projects
Commit d7e29f4b authored by Lisa Carey's avatar Lisa Carey
Browse files

Implementing Tim's edits

parent c34e67fa
No related branches found
No related tags found
No related merge requests found
...@@ -26,7 +26,7 @@ Hello World method. ...@@ -26,7 +26,7 @@ Hello World method.
- Create a Go client that accesses the same Java server. - Create a Go client that accesses the same Java server.
- Update the service with more advanced features like RPC streaming. - Update the service with more advanced features like RPC streaming.
The complete code for the example is available in [wherever we put it]. You can The complete code for the example is available in the `grpc-common` GitHub repository. You can
work along with the example and hack on the code in the comfort of your own work along with the example and hack on the code in the comfort of your own
computer, giving you hands-on practice of really writing computer, giving you hands-on practice of really writing
gRPC code. We use the Git versioning system for source code management: gRPC code. We use the Git versioning system for source code management:
...@@ -174,7 +174,7 @@ to generated code. As we're creating Java code, we use the gRPC Java plugin. ...@@ -174,7 +174,7 @@ to generated code. As we're creating Java code, we use the gRPC Java plugin.
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
...@@ -182,7 +182,7 @@ $ popd ...@@ -182,7 +182,7 @@ $ popd
To use it to generate the code: To use it to generate the code:
``` ```sh
$ mkdir -p src/main/java $ mkdir -p src/main/java
$ protoc -I . helloworld.proto $ protoc -I . helloworld.proto
--plugin=protoc-gen-grpc=external/grpc_java/bins/opt/java_plugin \ --plugin=protoc-gen-grpc=external/grpc_java/bins/opt/java_plugin \
...@@ -194,27 +194,25 @@ This generates the following classes, which contain all the generated code we ne ...@@ -194,27 +194,25 @@ This generates the following classes, which contain all the generated code we ne
- [`Helloworld.java`](java/src/main/java/ex/grpc/Helloworld.java), which has all the protocol buffer code to populate, serialize, and retrieve our `HelloRequest` and `HelloReply` message types - [`Helloworld.java`](java/src/main/java/ex/grpc/Helloworld.java), which has all the protocol buffer code to populate, serialize, and retrieve our `HelloRequest` and `HelloReply` message types
- [`GreetingsGrpc.java`](java/src/main/java/ex/grpc/GreetingsGrpc.java), which contains (along with some other useful code): - [`GreetingsGrpc.java`](java/src/main/java/ex/grpc/GreetingsGrpc.java), which contains (along with some other useful code):
- an interface for `Greetings` servers to implement - an interface for `Greetings` servers to implement
``` ```java
public static interface Greetings { public static interface Greetings {
public void hello(ex.grpc.Helloworld.HelloRequest request, public void hello(ex.grpc.Helloworld.HelloRequest request,
com.google.net.stubby.stub.StreamObserver<ex.grpc.Helloworld.HelloReply> responseObserver); com.google.net.stubby.stub.StreamObserver<ex.grpc.Helloworld.HelloReply> responseObserver);
} }
``` ```
- _stub_ classes that clients can use to talk to a `Greetings` server. - _stub_ classes that clients can use to talk to a `Greetings` server.
``` ```java
public static class GreetingsStub extends public static class GreetingsStub extends
com.google.net.stubby.stub.AbstractStub<GreetingsStub, GreetingsServiceDescriptor> com.google.net.stubby.stub.AbstractStub<GreetingsStub, GreetingsServiceDescriptor>
implements Greetings { implements Greetings {
... ...
} }
``` ```
_Does gRPC output multiple Java classes per proto by default?_
<a name="server"></a> <a name="server"></a>
### Writing a server ### Writing a server
...@@ -233,7 +231,7 @@ Our server application has two classes: ...@@ -233,7 +231,7 @@ Our server application has two classes:
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(
...@@ -262,7 +260,7 @@ number of important features of gRPC being used here: ...@@ -262,7 +260,7 @@ number of important features of gRPC being used here:
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()))
...@@ -302,7 +300,7 @@ transport handling; its constructor accepts the host name and port of the ...@@ -302,7 +300,7 @@ transport handling; its constructor accepts the host name and port of the
service. The channel in turn is used to construct the Stub. service. The channel in turn is used to construct the Stub.
``` ```java
private final ChannelImpl channel; private final ChannelImpl channel;
private final GreetingGrpc.GreetingBlockingStub blockingStub; private final GreetingGrpc.GreetingBlockingStub blockingStub;
...@@ -324,7 +322,7 @@ It: ...@@ -324,7 +322,7 @@ It:
- prints out the greeting - prints out the greeting
``` ```java
public void greet(String name) { public void greet(String name) {
logger.debug("Will try to greet " + name + " ..."); logger.debug("Will try to greet " + name + " ...");
try { try {
...@@ -344,7 +342,7 @@ It: ...@@ -344,7 +342,7 @@ It:
The main method puts together the example so that it can be run from a command The main method puts together the example so that it can be run from a command
line. line.
``` ```java
/* Access a service running on the local machine on port 50051 */ /* Access a service running on the local machine on port 50051 */
HelloClient client = new HelloClient("localhost", 50051); HelloClient client = new HelloClient("localhost", 50051);
String user = "world"; String user = "world";
...@@ -379,13 +377,13 @@ $ mvn package ...@@ -379,13 +377,13 @@ $ 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 $ ./run_greetings_client.sh
``` ```
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment