blob: a29955338a69a424230918920722456cccf96528 [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
25$ cd java
26$ mvn install
rockingc60f0172015-02-25 12:34:28 -080027$ cd ../javanano
28$ mvn install
Eric Andersonfb28ad22015-01-29 15:00:58 -080029```
30
31If you are comfortable with C++ compilation and autotools, you can specify a
32--prefix for protobuf and use -I in CXXFLAGS, -L in LDFLAGS, LD\_LIBRARY\_PATH,
33and PATH to reference it. The environment variables will be used when building
34grpc-java.
35
Louis Ryan65d64cd2015-02-18 14:51:42 -080036Protobuf installs to /usr/local by default.
37If /usr/local/lib is not in your library search path, you can add it by running:
38```
39$ sudo sh -c 'echo /usr/local/lib >> /etc/ld.so.conf'
40$ sudo ldconfig
41```
42
Eric Andersonfb28ad22015-01-29 15:00:58 -080043Now to build grpc-java itself:
44```
45$ ./gradlew install
46```
47
Eric Anderson456216b2015-03-02 16:58:27 -080048When building on Windows and VC++, you need to specify project properties for
49Gradle to find protobuf:
50```
51.\gradlew install -Pprotobuf.include=C:\path\to\protobuf-3.0.0-alpha-2\src ^
52 -Pprotobuf.libs=C:\path\to\protobuf-3.0.0-alpha-2\vsprojects\Release
53```
54
55Since specifying those properties every build is bothersome, you can instead
56create %HOMEDRIVE%%HOMEPATH%\.gradle\gradle.properties with contents like:
57```
58protobuf.include=C:\\path\\to\\protobuf-3.0.0-alpha-2\\src
59protobuf.libs=C:\\path\\to\\protobuf-3.0.0-alpha-2\\vsprojects\\Release
60```
61
Eric Andersonfb28ad22015-01-29 15:00:58 -080062Navigating Around the Source
63----------------------------
64
ejonad4531da2014-12-15 10:24:42 -080065Heres a quick readers guide to the code to help folks get started. At a high level there are three distinct layers
66to the library: stub, channel & transport.
67
Eric Andersonfb28ad22015-01-29 15:00:58 -080068### Stub
ejonad4531da2014-12-15 10:24:42 -080069
70The 'stub' layer is what is exposed to most developers and provides type-safe bindings to whatever
71datamodel/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.
72
73#### Key Interfaces
74
nmittlerf8314582015-01-27 10:25:39 -080075[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 -080076
77
Eric Andersonfb28ad22015-01-29 15:00:58 -080078### Channel
ejonad4531da2014-12-15 10:24:42 -080079
80The '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.
81
82#### Common
83
nmittlerf8314582015-01-27 10:25:39 -080084* [Metadata - headers & trailers](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/Metadata.java)
85* [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 -080086
87#### Client
nmittlerf8314582015-01-27 10:25:39 -080088* [Channel - client side binding](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/Channel.java)
89* [Call](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/Call.java)
90* [Client Interceptor](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/ClientInterceptor.java)
ejonad4531da2014-12-15 10:24:42 -080091
92#### Server
nmittlerf8314582015-01-27 10:25:39 -080093* [Server call handler - analog to Channel on server](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/ServerCallHandler.java)
94* [Server Call](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/ServerCall.java)
ejonad4531da2014-12-15 10:24:42 -080095
96
Eric Andersonfb28ad22015-01-29 15:00:58 -080097### Transport
ejonad4531da2014-12-15 10:24:42 -080098
99The '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.
100
101#### Common
102
nmittlerf8314582015-01-27 10:25:39 -0800103* [Stream](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/transport/Stream.java)
104* [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 -0800105
106#### Client
107
nmittlerf8314582015-01-27 10:25:39 -0800108* [Client Stream](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/transport/ClientStream.java)
109* [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 -0800110
111#### Server
112
nmittlerf8314582015-01-27 10:25:39 -0800113* [Server Stream](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/transport/ServerStream.java)
114* [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 -0800115
116
Eric Andersonfb28ad22015-01-29 15:00:58 -0800117### Examples
ejonad4531da2014-12-15 10:24:42 -0800118
nmittlerf8314582015-01-27 10:25:39 -0800119Tests 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