gRPC is a high-performance RPC framework that supports multiple languages, concise service definitions, and streaming. It is an ideal choice for building scalable and efficient microservice systems.
This project provides out-of-the-box, highly extensible Spring Boot starters for the gRPC ecosystem, making the integration of Spring Boot and gRPC seamless and native.
implementation(platform("io.github.danielliu1123:grpc-starter-dependencies:<latest>"))
implementation("io.github.danielliu1123:grpc-boot-starter")
implementation("io.grpc:grpc-testing-proto")
@SpringBootApplication
public class QuickStartApp extends SimpleServiceGrpc.SimpleServiceImplBase {
public static void main(String[] args) {
new SpringApplicationBuilder(QuickStartApp.class)
.properties("grpc.client.base-packages=io.grpc") // scan packages for gRPC clients
.properties("grpc.client.authority=127.0.0.1:9090") // default authority for gRPC clients
.run(args);
}
@Override
public void unaryRpc(SimpleRequest request, StreamObserver<SimpleResponse> r) {
var response = SimpleResponse.newBuilder()
.setResponseMessage("Hello " + request.getRequestMessage())
.build();
r.onNext(response);
r.onCompleted();
}
@Bean
ApplicationRunner runner(SimpleServiceGrpc.SimpleServiceBlockingStub stub) { // inject gRPC client
return args -> {
var response = stub.unaryRpc(SimpleRequest.newBuilder().setRequestMessage("World!").build());
System.out.println(response.getResponseMessage());
};
}
}
Refer to quick-start.
- Dependency management for gRPC-related libraries
- gRPC server autoconfiguration
- gRPC client autoconfiguration
- gRPC HTTP transcoding: Support both gRPC and HTTP/JSON with a single codebase.
- Protobuf validation: Protobuf message validation using protovalidate and protoc-gen-validate.
- Metrics: Integrate Spring Boot Actuator with gRPC services.
- Tracing: Integrate Spring Boot Actuator with gRPC server and client.
- Testing: Integration with
SpringBootTest
.
Go to Reference Documentation for more information.
./gradlew build
This project is governed by the Code of Conduct. By participating, you are expected to uphold this code of conduct. Please report unacceptable behavior to llw599502537@gmail.com.
Use the issue tracker for bug reports, feature requests, and submitting pull requests.
If you would like to contribute to the project, please refer to Contributing.
The MIT License.