blob: a74f3caf94a71119cc7e2ac5cb4498ef079a0e90 [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
Kun Zhang2f749712015-05-06 13:10:28 -070022the source tree, you can skip this chapter and add ``skipCodegen=true``
23to ``<project-root>/gradle.properties``. It will make the build script skip the
Kun Zhang111f6dd2015-05-05 16:11:27 -070024build 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 ^
Kun Zhang2f749712015-05-06 13:10:28 -070076 -PvcProtobufInclude=C:\path\to\protobuf-3.0.0-alpha-2\src ^
77 -PvcProtobufLibs=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 Zhang2f749712015-05-06 13:10:28 -070081create ``<project-root>\gradle.properties`` with contents like:
Eric Anderson456216b2015-03-02 16:58:27 -080082```
Kun Zhang2f749712015-05-06 13:10:28 -070083vcProtobufInclude=C:\\path\\to\\protobuf-3.0.0-alpha-2\\src
84vcProtobufLibs=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
Kun Zhang2f749712015-05-06 13:10:28 -070093default. To override this default and use MinGW, add ``-PvcDisable=true``
94to your Gradle command line or add ``vcDisable=true`` to your
95``<project-root>\gradle.properties``.
Kun Zhang221c5342015-04-29 18:16:15 -070096
Eric Andersonfb28ad22015-01-29 15:00:58 -080097Navigating Around the Source
98----------------------------
99
ejonad4531da2014-12-15 10:24:42 -0800100Heres 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 -0700101to the library: stub, channel & transport.
ejonad4531da2014-12-15 10:24:42 -0800102
Eric Andersonfb28ad22015-01-29 15:00:58 -0800103### Stub
ejonad4531da2014-12-15 10:24:42 -0800104
105The 'stub' layer is what is exposed to most developers and provides type-safe bindings to whatever
106datamodel/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.
107
108#### Key Interfaces
109
nmittlerf8314582015-01-27 10:25:39 -0800110[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 -0800111
112
Eric Andersonfb28ad22015-01-29 15:00:58 -0800113### Channel
ejonad4531da2014-12-15 10:24:42 -0800114
115The '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.
116
117#### Common
118
nmittlerf8314582015-01-27 10:25:39 -0800119* [Metadata - headers & trailers](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/Metadata.java)
120* [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 -0800121
122#### Client
nmittlerf8314582015-01-27 10:25:39 -0800123* [Channel - client side binding](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/Channel.java)
124* [Call](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/Call.java)
125* [Client Interceptor](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/ClientInterceptor.java)
ejonad4531da2014-12-15 10:24:42 -0800126
127#### Server
nmittlerf8314582015-01-27 10:25:39 -0800128* [Server call handler - analog to Channel on server](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/ServerCallHandler.java)
129* [Server Call](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/ServerCall.java)
ejonad4531da2014-12-15 10:24:42 -0800130
131
Eric Andersonfb28ad22015-01-29 15:00:58 -0800132### Transport
ejonad4531da2014-12-15 10:24:42 -0800133
134The '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.
135
136#### Common
137
nmittlerf8314582015-01-27 10:25:39 -0800138* [Stream](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/transport/Stream.java)
139* [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 -0800140
141#### Client
142
nmittlerf8314582015-01-27 10:25:39 -0800143* [Client Stream](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/transport/ClientStream.java)
144* [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 -0800145
146#### Server
147
nmittlerf8314582015-01-27 10:25:39 -0800148* [Server Stream](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/transport/ServerStream.java)
149* [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 -0800150
151
Eric Andersonfb28ad22015-01-29 15:00:58 -0800152### Examples
ejonad4531da2014-12-15 10:24:42 -0800153
nmittlerf8314582015-01-27 10:25:39 -0800154Tests 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