-
Java
-
8+=
-
8- -> use specific branch
Java version gRPC Branch 7 1.41.x
-
-
Android
- minSdkVersion 21+= (Lollipop)
- +21 -- supported with -- Java 8 language desugaring.
- if you want TLS -> use Play Services Dynamic Security Provider -- Check Security Readme --
- minSdkVersion 21+= (Lollipop)
- quick start guide
- guided tour
- gRPC basics
- more explanatory
- Standalone projects / show the use of gRPC
- JARs
- Maven with non-Android
<dependency> <groupId>io.grpc</groupId> <artifactId>grpc-netty-shaded</artifactId> <version>1.63.0</version> <scope>runtime</scope> </dependency> <dependency> <groupId>io.grpc</groupId> <artifactId>grpc-protobuf</artifactId> <version>1.63.0</version> </dependency> <dependency> <groupId>io.grpc</groupId> <artifactId>grpc-stub</artifactId> <version>1.63.0</version> </dependency> <dependency> <!-- necessary for Java 9+ --> <groupId>org.apache.tomcat</groupId> <artifactId>annotations-api</artifactId> <version>6.0.53</version> <scope>provided</scope> </dependency>
- Gradle / non-Android
runtimeOnly 'io.grpc:grpc-netty-shaded:1.63.0' implementation 'io.grpc:grpc-protobuf:1.63.0' implementation 'io.grpc:grpc-stub:1.63.0' compileOnly 'org.apache.tomcat:annotations-api:6.0.53' // necessary for Java 9+
- Android client
grpc-okhttp
-- instead of --grpc-netty-shaded
andgrpc-protobuf-lite
-- instead of --grpc-protobuf
implementation 'io.grpc:grpc-okhttp:1.63.0' implementation 'io.grpc:grpc-protobuf-lite:1.63.0' implementation 'io.grpc:grpc-stub:1.63.0' compileOnly 'org.apache.tomcat:annotations-api:6.0.53' // necessary for Java 9+
- Bazel
- Maven -- (with the GAVs from above) --OR
@io_grpc_grpc_java//api
et al (see below)
- Development snapshots
- For protobuf-based codegen
- -> put your proto files in
src/main/proto
&src/test/proto
- -> put your proto files in
- For protobuf-based codegen + integrated with the Maven build system
- -> use protobuf-maven-plugin
- if Eclipse and NetBeans users - > check
os-maven-plugin
's IDE documentation)
<build> <extensions> <extension> <groupId>kr.motd.maven</groupId> <artifactId>os-maven-plugin</artifactId> <version>1.7.1</version> </extension> </extensions> <plugins> <plugin> <groupId>org.xolstice.maven.plugins</groupId> <artifactId>protobuf-maven-plugin</artifactId> <version>0.6.1</version> <configuration> <protocArtifact>com.google.protobuf:protoc:3.25.1:exe:${os.detected.classifier}</protocArtifact> <pluginId>grpc-java</pluginId> <pluginArtifact>io.grpc:protoc-gen-grpc-java:1.63.0:exe:${os.detected.classifier}</pluginArtifact> </configuration> <executions> <execution> <goals> <goal>compile</goal> <goal>compile-custom</goal> </goals> </execution> </executions> </plugin> </plugins> </build>
- if Eclipse and NetBeans users - > check
- -> use protobuf-maven-plugin
- For non-Android protobuf-based codegen + integrated with the Gradle build system
- -> use protobuf-gradle-plugin:
plugins { id 'com.google.protobuf' version '0.9.4' } protobuf { protoc { artifact = "com.google.protobuf:protoc:3.25.1" } plugins { grpc { artifact = 'io.grpc:protoc-gen-grpc-java:1.63.0' } } generateProtoTasks { all()*.plugins { grpc {} } } }
- prebuilt
protoc-gen-grpc-java
binary uses glibc on Linux- if you are compiling on Alpine Linux -> use Alpine grpc-java package -- which uses
musl
instead --
- if you are compiling on Alpine Linux -> use Alpine grpc-java package -- which uses
- prebuilt
- -> use protobuf-gradle-plugin:
- For Android protobuf-based codegen + integrated with the Gradle build system
-
-> use
protobuf-gradle-plugin
/ specify the 'lite' optionsplugins { id 'com.google.protobuf' version '0.9.4' } protobuf { protoc { artifact = "com.google.protobuf:protoc:3.25.1" } plugins { grpc { artifact = 'io.grpc:protoc-gen-grpc-java:1.63.0' } } generateProtoTasks { all().each { task -> task.builtins { java { option 'lite' } } task.plugins { grpc { option 'lite' } } } } }
-
- For Bazel
- -> use
proto_library
&java_proto_library
- no
load()
required
- no
load("@io_grpc_grpc_java//:java_grpc_library.bzl", "java_grpc_library")
- -> use
- Based on the annotations of the APIs
@Internal
- uses
- internal use by the gRPC library
- NOT by gRPC users
- uses
@ExperimentalApi
- == subject to change in future releases
- -> NOT depend on them
- == subject to change in future releases
- grpc-java-api-checker
- := Error Prone plugin /
- allows
- checking usages in any library code / depends on gRPC of
@ExperimentalApi
@Internal
- checking consumption in non-library code of
@ExperimentalApi
@Internal
- checking usages in any library code / depends on gRPC of
- allows
- := Error Prone plugin /
⚠️ JUST required, if you are making changes to gRPC-Java⚠️ - Check compiling instructions
- There are three distinct layers to the library
- Stub
- Channel
- Transport
- := layer /
- exposed to most developers
- provides
- type-safe bindings -- to -- whatever datamodel/IDL/interface you are adapting
- built-in plugin to the protocol-buffers compiler
- based on
.proto
files -- generates -- Stub interfaces
- based on
- to other datamodel/IDL are easy and encouraged (❓to build)
- built-in plugin to the protocol-buffers compiler
- type-safe bindings -- to -- whatever datamodel/IDL/interface you are adapting
- := layer /
- abstraction over Transport handling
- vs Stub
- exposes more behavior to the application
- uses
- interception/decoration
- application frameworks for cross-cutting concerns -- Example: logging, monitoring, auth, etc. --
- := layer /
- characteristics
- their interfaces are abstract just enough -- to allow -- plugging in of different implementations
- built-in implementations
- Netty-based HTTP/2 transport
- based on Netty
- 👁️ NOT 👁️ officially supported on Android
- 👁 exist a "grpc-netty-shaded" version 👁
- 👁 generally preferred 👁
- Reasons: 🧠less dependency management & easier to upgrade 🧠
- 👁 generally preferred 👁
- OkHttp-based HTTP/2 transport
- in-process transport
- uses
- process with the server == process with the client
- testing
- uses
- Binder transport
- uses
- Android cross-process communication | single device
- uses
- Netty-based HTTP/2 transport
- built-in implementations
- internal to gRPC
- vs core API under package
io.grpc
- weaker API guarantees
- their interfaces are abstract just enough -- to allow -- plugging in of different implementations
- in charge of
- put and take bytes off the wire
- characteristics