How jdk-plus/spring-boot-starter-grpc works
Main Components
• gRPC Server Components:
• Auto-configuration classes (e.g., GrpcAutoConfiguration, GrpcServerFactory, GrpcServerLifecycle) which set up and manage the server.
• Annotation components (e.g., @GrpcService, EnableGrpcServer) that enable gRPC service exposure.
• Interceptor configuration for the server (global interceptors, service-specific interceptors defined via GrpcServiceInterceptorConfigurer).
• Service registration modules (IGrpcServiceRegister implementations) for registering and deregistering the node (using tools such as etcd).
• gRPC Client Components:
• Auto-configuration for the client (GrpcClientAutoConfiguration) with support for a default service address, name resolvers, and custom interceptors.
• Annotation-driven clients (e.g., @GrpcClient on stub injection) that allow for simplified remote call creation.
• Factories for creating different types of gRPC stubs (e.g., AsyncStubFactory, BlockingStubFactory, FutureStubFactory, StandardGrpcStubFactory, FallbackStubFactory).
• NameResolver and client configuration (GrpcNameResolver, GrpcNameResolverProvider, INameResolverConfigurer) for service discovery from external configuration centers.
• Client interceptors (e.g., GrpcClientBeanPostProcessor, ClientBytesMetaDataInterceptor, and marshallers) that handle request metadata, encryption, or other cross-cutting concerns.
• Support and Utility Components:
• Global interceptor registries (GlobalGrpcInterceptorRegistry) for both client and server.
• Common utility classes (GrpcUtils) and configuration property classes (GrpcPlusProperties, GrpcPlusClientProperties) that centralize configuration.
• Annotation definitions (the various annotations in the annotation package) to drive integration with the Spring context.
• Additional selectors for choosing between multiple server and client beans (GrpcClientSelector, GrpcServerSelector).
Relationships and Interactions
• For the Server side, show that the Spring Boot auto-configuration reads properties (from application.properties/yaml) and sets up the server components, registers the available gRPC service beans (annotated with @GrpcService), and then wires in defined interceptors.
• For the Client side, indicate that the auto-configuration and bean post-processors (GrpcClientBeanPostProcessor) scan and process fields annotated with @GrpcClient, creating stub instances through the various Stub Factories. Also show how the NameResolver and INameResolverConfigurer interfaces are utilized to fetch configuration information (even via external sources, e.g., etcd) for service discovery.
• From the application configuration → Auto-configuration classes.
• From Auto-configuration → Factory beans and Interceptors → Actual gRPC stub creation.
• From gRPC service calls on the client → gRPC Server (actual RPC call) → Business logic execution.
• From the service registration components to external configuration centers (like etcd) for registering and discovering service nodes.
Architectural Patterns and Principles
• Modularization: The separation into packages (client, server, global, factory, interceptor, etc) reflects a clean separation of concerns.
• Dependency Injection and Auto-configuration: Leveraging Spring Boot’s auto-configuration to wire everything together automatically.
• Annotation-driven development: Custom annotations drive the discovery and configuration of services and clients.
Relevant Technologies, Frameworks, and Libraries
• Spring Boot – for auto-configuration and dependency injection.
• gRPC – as the underlying RPC framework.
• (Optionally) etcd, zookeeper, or redis – for service registration and discovery (as demonstrated in the README sample code).
• Protobuf & the protobuf-maven-plugin – for code generation from .proto files.
Final Recommendation
• Start at the highest abstraction level (overall architecture) and then drill down to detailed components (like the factories and interceptors).