Class GrpcTransportConfig
This configuration class allows customization of the gRPC channel factory used for communication with A2A agents. Unlike other transports, gRPC requires a channel factory to be explicitly provided - there is no default implementation.
Channel Factory Requirement: You must provide a Function<String, Channel>
that creates gRPC channels from agent URLs. This gives you full control over channel
configuration including connection pooling, TLS, load balancing, and interceptors.
Basic usage with ManagedChannel:
// Simple insecure channel for development
Function<String, Channel> channelFactory = url -> {
String target = extractTarget(url); // e.g., "localhost:9999"
return ManagedChannelBuilder.forTarget(target)
.usePlaintext()
.build();
};
GrpcTransportConfig config = new GrpcTransportConfigBuilder()
.channelFactory(channelFactory)
.build();
Client client = Client.builder(agentCard)
.withTransport(GrpcTransport.class, config)
.build();
Production configuration with TLS and timeouts:
Function<String, Channel> channelFactory = url -> {
String target = extractTarget(url);
return ManagedChannelBuilder.forTarget(target)
.useTransportSecurity()
.keepAliveTime(30, TimeUnit.SECONDS)
.idleTimeout(5, TimeUnit.MINUTES)
.maxInboundMessageSize(10 * 1024 * 1024) // 10MB
.build();
};
GrpcTransportConfig config = new GrpcTransportConfigBuilder()
.channelFactory(channelFactory)
.build();
With load balancing and connection pooling:
Function<String, Channel> channelFactory = url -> {
String target = extractTarget(url);
return ManagedChannelBuilder.forTarget(target)
.defaultLoadBalancingPolicy("round_robin")
.maxInboundMessageSize(50 * 1024 * 1024)
.keepAliveTime(30, TimeUnit.SECONDS)
.keepAliveTimeout(10, TimeUnit.SECONDS)
.build();
};
With interceptors:
GrpcTransportConfig config = new GrpcTransportConfigBuilder()
.channelFactory(channelFactory)
.addInterceptor(new LoggingInterceptor())
.addInterceptor(new AuthInterceptor(apiKey))
.build();
Channel Lifecycle: The channel factory creates channels on-demand when the client
connects to an agent. You are responsible for shutting down channels when the client is
closed. Consider using ManagedChannel.shutdown() in a cleanup hook.
- See Also:
-
Field Summary
Fields inherited from class ClientTransportConfig
interceptors, parameters -
Constructor Summary
ConstructorsConstructorDescriptionGrpcTransportConfig(Function<String, io.grpc.Channel> channelFactory) Create a gRPC transport configuration with a custom channel factory. -
Method Summary
Modifier and TypeMethodDescriptionGet the configured channel factory.Methods inherited from class ClientTransportConfig
getInterceptors, getParameters, setInterceptors, setParameters
-
Constructor Details
-
GrpcTransportConfig
Create a gRPC transport configuration with a custom channel factory.Consider using
GrpcTransportConfigBuilderinstead for a more fluent API.- Parameters:
channelFactory- function to create gRPC channels from agent URLs (must not be null)- Throws:
IllegalArgumentException- if channelFactory is null
-
-
Method Details
-
getChannelFactory
-