Skip to content

APiGen gRPC Module

gRPC support for inter-service communication in APiGen applications.

Features

  • Server Infrastructure: GrpcServer wrapper with fluent builder API
  • Client Infrastructure: GrpcChannelFactory for managed channel creation
  • Interceptors: Logging, Authentication, and Exception handling
  • Health Checks: HealthServiceManager for service health monitoring
  • Proto Definitions: Common types (pagination, errors, audit info)

Quick Start

1. Enable gRPC

yaml
apigen:
  grpc:
    enabled: true
    server:
      port: 9090

2. Create a gRPC Server

java
@Configuration
public class GrpcServerConfig {

    @Bean
    public GrpcServer grpcServer(
            List<BindableService> services,
            List<ServerInterceptor> interceptors) throws IOException {

        return GrpcServer.builder(9090)
            .addServices(services)
            .addInterceptors(interceptors)
            .build()
            .start();
    }
}

3. Create a Client

java
@Service
public class ProductClient {

    private final GrpcChannelFactory channelFactory;
    private final ProductServiceGrpc.ProductServiceBlockingStub stub;

    public ProductClient(GrpcChannelFactory channelFactory) {
        this.channelFactory = channelFactory;
        ManagedChannel channel = channelFactory.getChannel("product-service:9090", true);
        this.stub = ProductServiceGrpc.newBlockingStub(channel);
    }
}

Configuration Properties

PropertyDefaultDescription
apigen.grpc.enabledfalseEnable gRPC support
apigen.grpc.server.port9090gRPC server port
apigen.grpc.client.deadline-ms10000Default deadline
apigen.grpc.client.use-plaintextfalseUse plaintext (no TLS)

Released under the MIT License.