blob: 4b85194a392afe6a73b4a2b6c61f5b2087cb5928 [file] [log] [blame] [view]
Kun Zhangd32bb472015-05-06 16:15:53 -07001gRPC-Java - An RPC library and framework
2========================================
3
4[![Build Status](https://travis-ci.org/grpc/grpc-java.svg?branch=master)](https://travis-ci.org/grpc/grpc-java)
ejonad4531da2014-12-15 10:24:42 -08005
Eric Andersonfb28ad22015-01-29 15:00:58 -08006How to Build
7------------
8
Kun Zhangfd0aed22015-04-30 17:29:17 -07009### Build Netty
Jakob Buchgraberc56cec72015-03-11 13:44:32 -070010grpc-java requires Netty 4.1, which is still in flux. The version we need can be
Eric Andersonb10aaf82015-02-19 13:14:00 -080011found in the lib/netty submodule, which requires Maven 3.2 or higher to build:
Eric Andersonfb28ad22015-01-29 15:00:58 -080012```
13$ git submodule update --init
14$ cd lib/netty
15$ mvn install -pl codec-http2 -am -DskipTests=true
16```
17
Kun Zhangfd0aed22015-04-30 17:29:17 -070018### Build Protobuf
Kun Zhang111f6dd2015-05-05 16:11:27 -070019The codegen plugin is C++ code and requires protobuf 3.0.0-alpha-2.
20
21If you are not changing the codegen plugin, nor any of the ``.proto`` files in
22the source tree, you can skip this chapter and add ``grpc.skip.codegen=true``
23to ``$HOME/.gradle/gradle.properties``. It will make the build script skip the
24build and invocation of the codegen, and use generated code that has been
25checked in.
Kun Zhangfd0aed22015-04-30 17:29:17 -070026
27For Linux, Mac and MinGW:
Eric Andersonfb28ad22015-01-29 15:00:58 -080028```
29$ git clone https://github.com/google/protobuf.git
30$ cd protobuf
Eric Andersona6f5fff2015-02-26 07:53:17 -080031$ git checkout v3.0.0-alpha-2
Eric Andersonfb28ad22015-01-29 15:00:58 -080032$ ./autogen.sh
33$ ./configure
34$ make
35$ make check
36$ sudo make install
Eric Andersonfb28ad22015-01-29 15:00:58 -080037```
38
39If you are comfortable with C++ compilation and autotools, you can specify a
Kun Zhangfd0aed22015-04-30 17:29:17 -070040``--prefix`` for Protobuf and use ``-I`` in ``CXXFLAGS``, ``-L`` in
41``LDFLAGS``, ``LD_LIBRARY_PATH``, and ``PATH`` to reference it. The
42environment variables will be used when building grpc-java.
Eric Andersonfb28ad22015-01-29 15:00:58 -080043
Kun Zhangfd0aed22015-04-30 17:29:17 -070044Protobuf installs to ``/usr/local`` by default.
45
46For Visual C++, please refer to the [Protobuf README](https://github.com/google/protobuf/blob/master/vsprojects/readme.txt)
47for how to compile Protobuf.
48
49#### Linux and MinGW
50If ``/usr/local/lib`` is not in your library search path, you can add it by running:
Louis Ryan65d64cd2015-02-18 14:51:42 -080051```
52$ sudo sh -c 'echo /usr/local/lib >> /etc/ld.so.conf'
53$ sudo ldconfig
54```
55
Kun Zhangfd0aed22015-04-30 17:29:17 -070056#### Mac
57Some versions of Mac OS X (e.g., 10.10) doesn't have ``/usr/local`` in the
Kun Zhang111f6dd2015-05-05 16:11:27 -070058default search paths for header files and libraries. It will fail the build of
59the codegen. To work around this, you will need to set environment variables:
Kun Zhangfd0aed22015-04-30 17:29:17 -070060```
61$ export CXXFLAGS="-I/usr/local/include" LDFLAGS="-L/usr/local/lib"
62```
63
64### Build GRPC
65On Linux, Mac or MinGW:
Eric Andersonfb28ad22015-01-29 15:00:58 -080066```
67$ ./gradlew install
68```
69
Kun Zhang221c5342015-04-29 18:16:15 -070070### Notes for Visual C++
71
Eric Anderson456216b2015-03-02 16:58:27 -080072When building on Windows and VC++, you need to specify project properties for
73Gradle to find protobuf:
74```
Kun Zhang221c5342015-04-29 18:16:15 -070075.\gradlew install ^
76 -Pvc.protobuf.include=C:\path\to\protobuf-3.0.0-alpha-2\src ^
77 -Pvc.protobuf.libs=C:\path\to\protobuf-3.0.0-alpha-2\vsprojects\Release
Eric Anderson456216b2015-03-02 16:58:27 -080078```
79
80Since specifying those properties every build is bothersome, you can instead
Kun Zhangfd0aed22015-04-30 17:29:17 -070081create ``%HOMEDRIVE%%HOMEPATH%\.gradle\gradle.properties`` with contents like:
Eric Anderson456216b2015-03-02 16:58:27 -080082```
Kun Zhang221c5342015-04-29 18:16:15 -070083vc.protobuf.include=C:\\path\\to\\protobuf-3.0.0-alpha-2\\src
84vc.protobuf.libs=C:\\path\\to\\protobuf-3.0.0-alpha-2\\vsprojects\\Release
Eric Anderson456216b2015-03-02 16:58:27 -080085```
86
Kun Zhang221c5342015-04-29 18:16:15 -070087The build script will build the codegen for the same architecture as the Java
88runtime installed on your system. If you are using 64-bit JVM, the codegen will
89be compiled for 64-bit, that means you must have compiled Protobuf in 64-bit.
90
91### Notes for MinGW on Windows
92If you have both MinGW and VC++ installed on Windows, VC++ will be used by
93default. To override this default and use MinGW, add ``-Dvc.disable`` to your
94Gradle command line.
95
Eric Andersonfb28ad22015-01-29 15:00:58 -080096Navigating Around the Source
97----------------------------
98
ejonad4531da2014-12-15 10:24:42 -080099Heres 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 -0700100to the library: stub, channel & transport.
ejonad4531da2014-12-15 10:24:42 -0800101
Eric Andersonfb28ad22015-01-29 15:00:58 -0800102### Stub
ejonad4531da2014-12-15 10:24:42 -0800103
104The 'stub' layer is what is exposed to most developers and provides type-safe bindings to whatever
105datamodel/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.
106
107#### Key Interfaces
108
nmittlerf8314582015-01-27 10:25:39 -0800109[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 -0800110
111
Eric Andersonfb28ad22015-01-29 15:00:58 -0800112### Channel
ejonad4531da2014-12-15 10:24:42 -0800113
114The '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.
115
116#### Common
117
nmittlerf8314582015-01-27 10:25:39 -0800118* [Metadata - headers & trailers](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/Metadata.java)
119* [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 -0800120
121#### Client
nmittlerf8314582015-01-27 10:25:39 -0800122* [Channel - client side binding](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/Channel.java)
123* [Call](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/Call.java)
124* [Client Interceptor](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/ClientInterceptor.java)
ejonad4531da2014-12-15 10:24:42 -0800125
126#### Server
nmittlerf8314582015-01-27 10:25:39 -0800127* [Server call handler - analog to Channel on server](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/ServerCallHandler.java)
128* [Server Call](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/ServerCall.java)
ejonad4531da2014-12-15 10:24:42 -0800129
130
Eric Andersonfb28ad22015-01-29 15:00:58 -0800131### Transport
ejonad4531da2014-12-15 10:24:42 -0800132
133The '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.
134
135#### Common
136
nmittlerf8314582015-01-27 10:25:39 -0800137* [Stream](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/transport/Stream.java)
138* [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 -0800139
140#### Client
141
nmittlerf8314582015-01-27 10:25:39 -0800142* [Client Stream](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/transport/ClientStream.java)
143* [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 -0800144
145#### Server
146
nmittlerf8314582015-01-27 10:25:39 -0800147* [Server Stream](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/transport/ServerStream.java)
148* [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 -0800149
150
Eric Andersonfb28ad22015-01-29 15:00:58 -0800151### Examples
ejonad4531da2014-12-15 10:24:42 -0800152
nmittlerf8314582015-01-27 10:25:39 -0800153Tests 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