Introduction
grpc-starter
provides a series of Spring Boot starters for the gRPC ecosystem,
offering autoconfiguration and highly extensible capabilities to enhance the integration between Spring Boot and gRPC.
Why Another gRPC Starter
There are already two gRPC Spring Boot starters:
So, why create another one? Here are the main reasons:
- The autoconfiguration for gRPC clients is not elegant enough; it does not fully follow the Spring bean lifecycle and requires additional annotations like
@GrpcClient
. We aim to use@Autowired
directly to inject gRPC clients. - The integration with the surrounding gRPC ecosystem is incomplete, lacking features like gRPC HTTP transcoding, Protobuf validation, test support, etc.
- Writing extensions is challenging due to the lack of suitable extension points.
Core Features
Client
- Autoconfigure gRPC clients: allowing direct injection with
@Autowired
and fully respecting the Spring Bean lifecycle. - Dynamic refreshing: Support to modify gRPC client configurations at runtime without restarting the application.
Server
- Autoconfigure gRPC servers: write your gRPC service implementation and expose it as a Spring bean, we will take care of the rest.
- Exception handling: offering
@ExceptionHandler
like exception handling for gRPC server through@GrpcAdvice
/@GrpcExceptionHandler
. - Health check.
Extensions
- gRPC HTTP transcoding: enabling a single codebase to support both gRPC and HTTP/JSON (like grpc-gateway but for Java).
- Protobuf validation: integrating with protovalidate and protoc-gen-validate.
- Metrics: supporting metrics through Spring Boot Actuator.
- Tracing: supporting tracing through Spring Boot Actuator.
- Test: integrating with
SpringBootTest
.
This framework is designed for extensibility, and you can easily extend it to suit your needs.
Project Structure
├── examples # Examples
├── grpc-boot-autoconfigure
│ ├── grpc-client-boot-autoconfigure # gRPC client autoconfiguration
│ └── grpc-server-boot-autoconfigure # gRPC server autoconfiguration
├── grpc-extensions
│ ├── grpc-metrics # Metrics extension
│ ├── grpc-test # Test extension
│ ├── grpc-tracing # Tracing extension
│ ├── grpc-transcoding # HTTP transcoding extension
│ └── grpc-validation # Protobuf validation extension
├── grpc-starter-dependencies # BOM
├── grpc-starters
│ ├── grpc-boot-starter # Core starter, including grpc-client-boot-starter and grpc-server-boot-starter
│ ├── grpc-client-boot-starter # gRPC client starter
│ ├── grpc-server-boot-starter # gRPC server starter
│ ├── grpc-starter-metrics # Metrics starter
│ ├── grpc-starter-protovalidate # Protobuf validation starter, implemented by protovalidate
│ ├── grpc-starter-test # Test starter
│ ├── grpc-starter-tracing # Tracing starter
│ ├── grpc-starter-transcoding # HTTP transcoding starter for WebMVC/WebFlux
│ └── grpc-starter-validation # Protobuf validation starter, implemented by protoc-gen-validate
└── website # Documentation, powered by Docusaurus
tip
Always uses the starters instead of the autoconfigure modules directly.