blob: b759cd931b9b6973183474c4927c31f435f17bd0 [file] [log] [blame] [view]
Kun Zhangd32bb472015-05-06 16:15:53 -07001gRPC-Java - An RPC library and framework
2========================================
3
Eric Anderson65291322015-05-15 11:57:05 -07004gRPC-Java works with JDK 6. TLS usage typically requires using Java 8, or Play
nmittler24830092015-05-28 13:12:56 -07005Services Dynamic Security Provider on Android. Please see the [Security
6Readme](SECURITY.md).
ejonad4531da2014-12-15 10:24:42 -08007
nmittlerb7a72c12015-09-24 12:03:23 -07008<table>
9 <tr>
10 <td><b>Homepage:</b></td>
11 <td><a href="http://www.grpc.io/">www.grpc.io</a></td>
12 </tr>
13 <tr>
14 <td><b>Mailing List:</b></td>
15 <td><a href="https://groups.google.com/forum/#!forum/grpc-io">grpc-io@googlegroups.com</a></td>
16 </tr>
17</table>
18
19[![Build Status](https://travis-ci.org/grpc/grpc-java.svg?branch=master)](https://travis-ci.org/grpc/grpc-java)
20[![Coverage Status](https://coveralls.io/repos/grpc/grpc-java/badge.svg?branch=master&service=github)](https://coveralls.io/github/grpc/grpc-java?branch=master)
21
Eric Anderson1eb16d92015-05-26 14:22:32 -070022Download
23--------
24
25Download [the JAR][]. Or for Maven, add to your `pom.xml`:
26```xml
27<dependency>
28 <groupId>io.grpc</groupId>
29 <artifactId>grpc-all</artifactId>
Carl Mastrangelo3c924fd2015-08-13 15:49:22 -070030 <version>0.8.0</version>
Eric Anderson1eb16d92015-05-26 14:22:32 -070031</dependency>
32```
33
34Or for Gradle, add to your dependencies:
35```gradle
Carl Mastrangelo3c924fd2015-08-13 15:49:22 -070036compile 'io.grpc:grpc-all:0.8.0'
Eric Anderson1eb16d92015-05-26 14:22:32 -070037```
38
Carl Mastrangelo3c924fd2015-08-13 15:49:22 -070039[the JAR]: https://search.maven.org/remote_content?g=io.grpc&a=grpc-all&v=0.8.0
Eric Anderson1eb16d92015-05-26 14:22:32 -070040
41Development snapshots are available in [Sonatypes's snapshot
42repository](https://oss.sonatype.org/content/repositories/snapshots/).
43
44For protobuf-based codegen integrated with the Maven build system, you can use
45[maven-protoc-plugin][]:
46```xml
Kun Zhang7a716272015-06-30 18:13:27 -070047<pluginRepositories>
48 <pluginRepository>
49 <releases>
50 <updatePolicy>never</updatePolicy>
51 </releases>
52 <snapshots>
53 <enabled>false</enabled>
54 </snapshots>
55 <id>central</id>
56 <name>Central Repository</name>
57 <url>https://repo.maven.apache.org/maven2</url>
58 </pluginRepository>
59 <pluginRepository>
60 <id>protoc-plugin</id>
61 <url>https://dl.bintray.com/sergei-ivanov/maven/</url>
62 </pluginRepository>
63</pluginRepositories>
Eric Anderson1eb16d92015-05-26 14:22:32 -070064<build>
65 <extensions>
66 <extension>
67 <groupId>kr.motd.maven</groupId>
68 <artifactId>os-maven-plugin</artifactId>
Artem Prigoda24c398e2015-09-16 22:52:26 +030069 <version>1.4.0.Final</version>
Eric Anderson1eb16d92015-05-26 14:22:32 -070070 </extension>
71 </extensions>
72 <plugins>
73 <plugin>
74 <groupId>com.google.protobuf.tools</groupId>
75 <artifactId>maven-protoc-plugin</artifactId>
76 <version>0.4.2</version>
77 <configuration>
Kun Zhang8bd8ed82015-07-22 09:19:52 -070078 <!--
79 The version of protoc must match protobuf-java. If you don't depend on
80 protobuf-java directly, you will be transitively depending on the
81 protobuf-java version that grpc depends on.
82 -->
Carl Mastrangelo3c924fd2015-08-13 15:49:22 -070083 <protocArtifact>com.google.protobuf:protoc:3.0.0-alpha-3.1:exe:${os.detected.classifier}</protocArtifact>
Eric Anderson1eb16d92015-05-26 14:22:32 -070084 <pluginId>grpc-java</pluginId>
Carl Mastrangelo3c924fd2015-08-13 15:49:22 -070085 <pluginArtifact>io.grpc:protoc-gen-grpc-java:0.8.0:exe:${os.detected.classifier}</pluginArtifact>
Eric Anderson1eb16d92015-05-26 14:22:32 -070086 </configuration>
87 <executions>
88 <execution>
89 <goals>
90 <goal>compile</goal>
91 <goal>compile-custom</goal>
92 </goals>
93 </execution>
94 </executions>
95 </plugin>
96 </plugins>
97</build>
98```
99
100[maven-protoc-plugin]: http://sergei-ivanov.github.io/maven-protoc-plugin/
101
102For protobuf-based codegen integrated with the Gradle build system, you can use
103[protobuf-gradle-plugin][]:
104```gradle
Kun Zhang8bd8ed82015-07-22 09:19:52 -0700105apply plugin: 'java'
Eric Anderson1eb16d92015-05-26 14:22:32 -0700106apply plugin: 'com.google.protobuf'
107
108buildscript {
109 repositories {
110 mavenCentral()
111 }
112 dependencies {
Kun Zhang137b2ef2015-08-03 11:10:22 -0700113 classpath 'com.google.protobuf:protobuf-gradle-plugin:0.6.1'
Eric Anderson1eb16d92015-05-26 14:22:32 -0700114 }
115}
116
Kun Zhang8bd8ed82015-07-22 09:19:52 -0700117protobuf {
118 protoc {
119 // The version of protoc must match protobuf-java. If you don't depend on
120 // protobuf-java directly, you will be transitively depending on the
121 // protobuf-java version that grpc depends on.
Carl Mastrangelo3c924fd2015-08-13 15:49:22 -0700122 artifact = "com.google.protobuf:protoc:3.0.0-alpha-3.1"
Kun Zhang8bd8ed82015-07-22 09:19:52 -0700123 }
124 plugins {
125 grpc {
Carl Mastrangelo3c924fd2015-08-13 15:49:22 -0700126 artifact = 'io.grpc:protoc-gen-grpc-java:0.8.0'
Kun Zhang8bd8ed82015-07-22 09:19:52 -0700127 }
128 }
129 generateProtoTasks {
130 all()*.plugins {
131 grpc {}
Eric Anderson1eb16d92015-05-26 14:22:32 -0700132 }
133 }
134}
Eric Anderson1eb16d92015-05-26 14:22:32 -0700135```
136
137[protobuf-gradle-plugin]: https://github.com/google/protobuf-gradle-plugin
138
Eric Andersonfb28ad22015-01-29 15:00:58 -0800139How to Build
140------------
141
Eric Anderson1b1c6462015-08-14 08:49:56 -0700142If you are making changes to gRPC-Java, see the [compiling
143instructions](COMPILING.md).
Kun Zhang9805e272015-05-12 17:03:19 -0700144
Eric Andersonfb28ad22015-01-29 15:00:58 -0800145Navigating Around the Source
146----------------------------
147
mekka99907942015-08-07 23:28:06 -0700148Here's a quick readers' guide to the code to help folks get started. At a high
Kun Zhangfc85a402015-08-05 16:48:15 -0700149level there are three distinct layers to the library: __Stub__, __Channel__ &
150__Transport__.
ejonad4531da2014-12-15 10:24:42 -0800151
Eric Andersonfb28ad22015-01-29 15:00:58 -0800152### Stub
ejonad4531da2014-12-15 10:24:42 -0800153
Kun Zhangfc85a402015-08-05 16:48:15 -0700154The Stub layer is what is exposed to most developers and provides type-safe
155bindings to whatever datamodel/IDL/interface you are adapting. gRPC comes with
156a [plugin](https://github.com/google/grpc-java/blob/master/compiler) to the
157protocol-buffers compiler that generates Stub interfaces out of `.proto` files,
158but bindings to other datamodel/IDL should be trivial to add and are welcome.
ejonad4531da2014-12-15 10:24:42 -0800159
160#### Key Interfaces
161
nmittlerf8314582015-01-27 10:25:39 -0800162[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 -0800163
Eric Andersonfb28ad22015-01-29 15:00:58 -0800164### Channel
ejonad4531da2014-12-15 10:24:42 -0800165
Kun Zhangfc85a402015-08-05 16:48:15 -0700166The Channel layer is an abstraction over Transport handling that is suitable for
167interception/decoration and exposes more behavior to the application than the
168Stub layer. It is intended to be easy for application frameworks to use this
169layer to address cross-cutting concerns such as logging, monitoring, auth etc.
170Flow-control is also exposed at this layer to allow more sophisticated
171applications to interact with it directly.
ejonad4531da2014-12-15 10:24:42 -0800172
173#### Common
174
nmittlerf8314582015-01-27 10:25:39 -0800175* [Metadata - headers & trailers](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/Metadata.java)
176* [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 -0800177
178#### Client
nmittlerf8314582015-01-27 10:25:39 -0800179* [Channel - client side binding](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/Channel.java)
Kun Zhang2ee4d022015-06-04 16:39:25 -0700180* [Client Call](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/ClientCall.java)
nmittlerf8314582015-01-27 10:25:39 -0800181* [Client Interceptor](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/ClientInterceptor.java)
ejonad4531da2014-12-15 10:24:42 -0800182
183#### Server
nmittlerf8314582015-01-27 10:25:39 -0800184* [Server call handler - analog to Channel on server](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/ServerCallHandler.java)
185* [Server Call](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/ServerCall.java)
ejonad4531da2014-12-15 10:24:42 -0800186
187
Eric Andersonfb28ad22015-01-29 15:00:58 -0800188### Transport
ejonad4531da2014-12-15 10:24:42 -0800189
mekka99907942015-08-07 23:28:06 -0700190The Transport layer does the heavy lifting of putting and taking bytes off the
Kun Zhangfc85a402015-08-05 16:48:15 -0700191wire. The interfaces to it are abstract just enough to allow plugging in of
192different implementations. Transports are modeled as `Stream` factories. The
193variation in interface between a server Stream and a client Stream exists to
194codify their differing semantics for cancellation and error reporting.
195
196Note the transport layer API is considered internal to gRPC and has weaker API
197guarantees than the core API under package `io.grpc`.
198
mekka99907942015-08-07 23:28:06 -0700199gRPC comes with three Transport implementations:
Kun Zhangfc85a402015-08-05 16:48:15 -0700200
2011. The [Netty-based](https://github.com/google/grpc-java/blob/master/netty)
202 transport is the main transport implementation based on
203 [Netty](http://netty.io). It is for both the client and the server.
2042. The [OkHttp-based](https://github.com/google/grpc-java/blob/master/okhttp)
205 transport is a lightweight transport based on
206 [OkHttp](http://square.github.io/okhttp/). It is mainly for use on Android
mekka99907942015-08-07 23:28:06 -0700207 and is for client only.
Kun Zhangfc85a402015-08-05 16:48:15 -07002083. The
Kun Zhange1bd6ef2015-08-11 11:17:39 -0700209 [inProcess](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/inprocess)
Kun Zhangfc85a402015-08-05 16:48:15 -0700210 transport is for when a server is in the same process as the client. It is
211 useful for testing.
ejonad4531da2014-12-15 10:24:42 -0800212
213#### Common
214
Kun Zhange1bd6ef2015-08-11 11:17:39 -0700215* [Stream](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/internal/Stream.java)
216* [Stream Listener](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/internal/StreamListener.java)
ejonad4531da2014-12-15 10:24:42 -0800217
218#### Client
219
Kun Zhange1bd6ef2015-08-11 11:17:39 -0700220* [Client Stream](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/internal/ClientStream.java)
221* [Client Stream Listener](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/internal/ClientStreamListener.java)
ejonad4531da2014-12-15 10:24:42 -0800222
223#### Server
224
Kun Zhange1bd6ef2015-08-11 11:17:39 -0700225* [Server Stream](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/internal/ServerStream.java)
226* [Server Stream Listener](https://github.com/google/grpc-java/blob/master/core/src/main/java/io/grpc/internal/ServerStreamListener.java)
ejonad4531da2014-12-15 10:24:42 -0800227
228
Eric Andersonfb28ad22015-01-29 15:00:58 -0800229### Examples
ejonad4531da2014-12-15 10:24:42 -0800230
Kun Zhangfc85a402015-08-05 16:48:15 -0700231Tests showing how these layers are composed to execute calls using protobuf
232messages can be found here
233https://github.com/google/grpc-java/tree/master/interop-testing/src/main/java/io/grpc/testing/integration