From 63e77966fd35ce0cbc88a70615069122ba33a1d9 Mon Sep 17 00:00:00 2001 From: Paul Grosu Date: Wed, 7 Dec 2016 16:06:48 -0500 Subject: submit --- .../1/figures/grpc-client-transport-handler.png | Bin 0 -> 67834 bytes .../1/figures/grpc-server-transport-handler.png | Bin 0 -> 60913 bytes chapter/1/gRPC.md | 31 +++++++++++++++++++-- 3 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 chapter/1/figures/grpc-client-transport-handler.png create mode 100644 chapter/1/figures/grpc-server-transport-handler.png diff --git a/chapter/1/figures/grpc-client-transport-handler.png b/chapter/1/figures/grpc-client-transport-handler.png new file mode 100644 index 0000000..edd5236 Binary files /dev/null and b/chapter/1/figures/grpc-client-transport-handler.png differ diff --git a/chapter/1/figures/grpc-server-transport-handler.png b/chapter/1/figures/grpc-server-transport-handler.png new file mode 100644 index 0000000..fe895c0 Binary files /dev/null and b/chapter/1/figures/grpc-server-transport-handler.png differ diff --git a/chapter/1/gRPC.md b/chapter/1/gRPC.md index 643edaa..953cfdd 100644 --- a/chapter/1/gRPC.md +++ b/chapter/1/gRPC.md @@ -175,6 +175,31 @@ The Transport Layer performs the retrieval and placing of binary protoc The Java implementation of gRPC been built with Mobile platform in mind and to provide that capability it requires JDK 6.0 to be supported. Though the core of gRPC is built with data centers in mind - specifically to support C/C++ for the Linux platform - the Java and Go implementations are two very reliable platform to experiment the microservice ecosystem implementations. +There are several moving parts to understanding how gRPC-Java works. The first important step is to ensure that the Client and Server stub inferface code get generated by the Protobuf plugin compiler. This is usually placed in your Gradle build file called `build.gradle` as follows: + +``` + compile 'io.grpc:grpc-netty:1.0.1' + compile 'io.grpc:grpc-protobuf:1.0.1' + compile 'io.grpc:grpc-stub:1.0.1' +``` + +When you build using Gradle, then the appropriate base code gets generated for you, which you can override to build your preferred implementation of the Client and Server. + +Since one has to implement the HTTP/2 protocol, the chosen method was to have a Metadata class that will convert the key-value pairs into HTTP/2 Headers and vice-versa for the Netty implementation via GrpcHttp2HeadersDecoder and GrpcHttp2OutboundHeaders. + +Another key insight is to understand that the code that handles the HTTP/2 conversion for the Client and the Server are being done via the NettyClientHandler.java and NettyServerHandler.java classes shown in Figures 8 and 9. + +

+
+ Figure 8: The Client Tranport Handler for gRPC-Java. +

+ +

+
+ Figure 9: The Server Tranport Handler for gRPC-Java. +

+ +

3.5.1 Downloading gRPC Java

The easiest way to download the gRPC-Java implementation is by performing the following command: @@ -183,7 +208,7 @@ The easiest way to download the gRPC-Java implementation is by performing the fo git clone -b v1.0.0 https://github.com/grpc/grpc-java.git ``` -Next compile on a Windows machine using Gradle using the following steps - and if you are using any Firewall software it might be necessary to temporarily disable it while compiling gRPC-Java as sockets are used for the tests: +Next compile on a Windows machine using Gradle (or Maven) using the following steps - and if you are using any Firewall software it might be necessary to temporarily disable it while compiling gRPC-Java as sockets are used for the tests: ``` cd grpc-java @@ -216,7 +241,7 @@ You should see the following:


- Figure 8: The Hello World gRPC Server. + Figure 10: The Hello World gRPC Server.

In the second of the two windows type the following command: @@ -229,7 +254,7 @@ You should see the following response:


- Figure 9: The Hello World gRPC Client and the response from the Server. + Figure 10: The Hello World gRPC Client and the response from the Server.

## References -- cgit v1.2.3