Package io.grpc

Interface ChannelConfigurator

  • Functional Interface:
    This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

    @ExperimentalApi("https://github.com/grpc/grpc-java/issues/12574")
    @FunctionalInterface
    public interface ChannelConfigurator
    A configurator for child channels created by gRPC's internal infrastructure.

    This interface allows users to inject configuration (such as credentials, interceptors, or flow control settings) into channels created automatically by gRPC for control plane operations. Common use cases include:

    • xDS control plane connections
    • Load Balancing helper channels (OOB channels)

    Usage Example:

    
     // 1. Define the configurator
     ChannelConfigurator configurator = builder -> {
       builder.maxInboundMessageSize(4 * 1024 * 1024);
     };
    
     // 2. Apply to parent channel - automatically used for ALL child channels
     ManagedChannel channel = ManagedChannelBuilder
         .forTarget("xds:///my-service")
         .childChannelConfigurator(configurator)
         .build();
     

    Implementations must be thread-safe as the configure methods may be invoked concurrently by multiple internal components.

    Since:
    1.83.0
    • Method Detail

      • configureChannelBuilder

        void configureChannelBuilder​(ManagedChannelBuilder<?> builder)
        Configures a builder for a new child channel.

        This method is invoked synchronously during the creation of the child channel, before ManagedChannelBuilder.build() is called.

        Note: Implementations must only apply configurations to the provided builder and must NOT call builder.build() themselves.

        Note: The provided builder is generic (?). Implementations should use universal configuration methods (like intercept(), userAgent()) on the builder rather than casting it to specific implementation types.

        Parameters:
        builder - the mutable channel builder for the new child channel