blob: 66dc8c3739bace5fb8404c919d72b6b72b68c4ab [file] [log] [blame] [view]
ejonad4531da2014-12-15 10:24:42 -08001grpc-java
2=========
3
Eric Andersonfb28ad22015-01-29 15:00:58 -08004How to Build
5------------
6
Jakob Buchgraberc56cec72015-03-11 13:44:32 -07007grpc-java requires Netty 4.1, which is still in flux. The version we need can be
Eric Andersonb10aaf82015-02-19 13:14:00 -08008found in the lib/netty submodule, which requires Maven 3.2 or higher to build:
Eric Andersonfb28ad22015-01-29 15:00:58 -08009```
10$ git submodule update --init
11$ cd lib/netty
12$ mvn install -pl codec-http2 -am -DskipTests=true
13```
14
Eric Andersona6f5fff2015-02-26 07:53:17 -080015The codegen plugin requires protobuf 3.0.0-alpha-2:
Eric Andersonfb28ad22015-01-29 15:00:58 -080016```
17$ git clone https://github.com/google/protobuf.git
18$ cd protobuf
Eric Andersona6f5fff2015-02-26 07:53:17 -080019$ git checkout v3.0.0-alpha-2
Eric Andersonfb28ad22015-01-29 15:00:58 -080020$ ./autogen.sh
21$ ./configure
22$ make
23$ make check
24$ sudo make install
Eric Andersonfb28ad22015-01-29 15:00:58 -080025```
26
27If you are comfortable with C++ compilation and autotools, you can specify a
28--prefix for protobuf and use -I in CXXFLAGS, -L in LDFLAGS, LD\_LIBRARY\_PATH,
29and PATH to reference it. The environment variables will be used when building
30grpc-java.
31
Louis Ryan65d64cd2015-02-18 14:51:42 -080032Protobuf installs to /usr/local by default.
33If /usr/local/lib is not in your library search path, you can add it by running:
34```
35$ sudo sh -c 'echo /usr/local/lib >> /etc/ld.so.conf'
36$ sudo ldconfig
37```
38
Eric Andersonfb28ad22015-01-29 15:00:58 -080039Now to build grpc-java itself:
40```
41$ ./gradlew install
42```
43
Eric Anderson456216b2015-03-02 16:58:27 -080044When building on Windows and VC++, you need to specify project properties for
45Gradle to find protobuf:
46```
47.\gradlew install -Pprotobuf.include=C:\path\to\protobuf-3.0.0-alpha-2\src ^
48 -Pprotobuf.libs=C:\path\to\protobuf-3.0.0-alpha-2\vsprojects\Release
49```
50
51Since specifying those properties every build is bothersome, you can instead
52create %HOMEDRIVE%%HOMEPATH%\.gradle\gradle.properties with contents like:
53```
54protobuf.include=C:\\path\\to\\protobuf-3.0.0-alpha-2\\src
55protobuf.libs=C:\\path\\to\\protobuf-3.0.0-alpha-2\\vsprojects\\Release
56```
57
Eric Andersonfb28ad22015-01-29 15:00:58 -080058Navigating Around the Source
59----------------------------
60
ejonad4531da2014-12-15 10:24:42 -080061Heres a quick readers guide to the code to help folks get started. At a high level there are three distinct layers
Kun Zhanga8ef36a2015-04-22 14:46:07 -070062to the library: stub, channel & transport.
ejonad4531da2014-12-15 10:24:42 -080063
Eric Andersonfb28ad22015-01-29 15:00:58 -080064### Stub
ejonad4531da2014-12-15 10:24:42 -080065
66The 'stub' layer is what is exposed to most developers and provides type-safe bindings to whatever
67datamodel/IDL/interface you are adapting. An example is provided of a binding to code generated by the protocol-buffers compiler but others should be trivial to add and are welcome.
68
69#### Key Interfaces
70
nmittlerf8314582015-01-27 10:25:39 -080071[Stream Observer](https://github.com/google/grpc-java/blob/master/stub/src/main/java/io/grpc/stub/StreamObserver.java)
ejonad4531da2014-12-15 10:24:42 -080072
73
Eric Andersonfb28ad22015-01-29 15:00:58 -080074### Channel
ejonad4531da2014-12-15 10:24:42 -080075
76The 'channel' layer is an abstraction over transport handling that is suitable for interception/decoration and exposes more behavior to the application than the stub layer. It is intended to be easy for application frameworks to use this layer to address cross-cutting concerns such as logging, monitoring, auth etc. Flow-control is also exposed at this layer to allow more sophisticated applications to interact with it directly.
77
78#### Common
79
nmittlerf8314582015-01-27 10:25:39 -080080* [Metadata - headers & trailers](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/Metadata.java)
81* [Status - error code namespace & handling](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/Status.java)
ejonad4531da2014-12-15 10:24:42 -080082
83#### Client
nmittlerf8314582015-01-27 10:25:39 -080084* [Channel - client side binding](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/Channel.java)
85* [Call](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/Call.java)
86* [Client Interceptor](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/ClientInterceptor.java)
ejonad4531da2014-12-15 10:24:42 -080087
88#### Server
nmittlerf8314582015-01-27 10:25:39 -080089* [Server call handler - analog to Channel on server](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/ServerCallHandler.java)
90* [Server Call](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/ServerCall.java)
ejonad4531da2014-12-15 10:24:42 -080091
92
Eric Andersonfb28ad22015-01-29 15:00:58 -080093### Transport
ejonad4531da2014-12-15 10:24:42 -080094
95The 'transport' layer does the heavy lifting of putting & taking bytes off the wire. The interfaces to it are abstract just enough to allow plugging in of different implementations. Transports are modeled as 'Stream' factories. The variation in interface between a server stream and a client stream exists to codify their differing semantics for cancellation and error reporting.
96
97#### Common
98
nmittlerf8314582015-01-27 10:25:39 -080099* [Stream](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/transport/Stream.java)
100* [Stream Listener](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/transport/StreamListener.java)
ejonad4531da2014-12-15 10:24:42 -0800101
102#### Client
103
nmittlerf8314582015-01-27 10:25:39 -0800104* [Client Stream](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/transport/ClientStream.java)
105* [Client Stream Listener](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/transport/ClientStreamListener.java)
ejonad4531da2014-12-15 10:24:42 -0800106
107#### Server
108
nmittlerf8314582015-01-27 10:25:39 -0800109* [Server Stream](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/transport/ServerStream.java)
110* [Server Stream Listener](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/transport/ServerStreamListener.java)
ejonad4531da2014-12-15 10:24:42 -0800111
112
Eric Andersonfb28ad22015-01-29 15:00:58 -0800113### Examples
ejonad4531da2014-12-15 10:24:42 -0800114
nmittlerf8314582015-01-27 10:25:39 -0800115Tests showing how these layers are composed to execute calls using protobuf messages can be found here https://github.com/google/grpc-java/tree/master/integration-testing/src/main/java/io/grpc/testing/integration