[go: nahoru, domu]

Skip to content

dancer1325/grpc-java

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gRPC-Java - An RPC library and framework

Supported Platforms

Getting Started

Ways to download

  • 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 and
    • grpc-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

Generated Code

  • For protobuf-based codegen
    • -> put your proto files in
      • src/main/proto &
      • src/test/proto
  • For protobuf-based codegen + integrated with the Maven build system
    • -> use protobuf-maven-plugin
      <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>
  • 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
  • For Android protobuf-based codegen + integrated with the Gradle build system
    • -> use protobuf-gradle-plugin / specify the 'lite' options

      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().each { task ->
            task.builtins {
              java { option 'lite' }
            }
            task.plugins {
              grpc { option 'lite' }
            }
          }
        }
      }
  • For Bazel

API Stability

  • Based on the annotations of the APIs
    • @Internal
      • uses
        • internal use by the gRPC library
        • NOT by gRPC users
    • @ExperimentalApi
      • == subject to change in future releases
        • -> NOT depend on them
  • 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

How to Build

High-level Components

  • There are three distinct layers to the library
    • Stub
    • Channel
    • Transport

Stub

  • := 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
        • to other datamodel/IDL are easy and encouraged (❓to build)

Channel

  • := 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. --

Transport

  • := 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 🧠
          • OkHttp-based HTTP/2 transport
            • := lightweight transport based on
            • uses
              • Android
          • in-process transport
            • uses
              • process with the server == process with the client
              • testing
          • Binder transport
            • uses
              • Android cross-process communication | single device
      • internal to gRPC
      • vs core API under package io.grpc
        • weaker API guarantees
    • in charge of
      • put and take bytes off the wire

About

The Java gRPC implementation. HTTP/2 based RPC

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages

  • Java 98.6%
  • Shell 0.5%
  • Starlark 0.4%
  • C++ 0.4%
  • Batchfile 0.1%
  • Dockerfile 0.0%