-
Notifications
You must be signed in to change notification settings - Fork 71
Description
Feature Request: Allow named channels to inherit default configuration
Problem
Currently, when a channel is explicitly configured in spring.grpc.client.channels.*, it does not inherit any settings from spring.grpc.client.default-channel.*.
Looking at GrpcClientProperties.getChannel():
public ChannelConfig getChannel(String name) {
if ("default".equals(name)) {
return this.defaultChannel;
}
ChannelConfig channel = this.channels.get(name);
if (channel != null) {
return channel; // Returns directly, no inheritance from defaultChannel
}
// defaultChannel.copy() is only used for channels NOT in the map
channel = this.defaultChannel.copy();
// ...
}Use Case
When configuring multiple gRPC clients, I want to set common properties once in default-channel/global and have all named channels inherit them:
spring.grpc.client:
default-channel:
max-inbound-message-size: 5MB
max-inbound-metadata-size: 1MB
enable-keep-alive: true
channels:
service-a:
address: service-a:6565
# Should inherit max-inbound-message-size, max-inbound-metadata-size, enable-keep-alive
service-b:
address: service-b:6565
# Should inherit from default-channel too### Current BehaviorEach named channel must explicitly define all properties, leading to repetition:
spring.grpc.client.channels:
service-a:
address: service-a:6565
max-inbound-message-size: 5MB
max-inbound-metadata-size: 1MB
service-b:
address: service-b:6565
max-inbound-message-size: 5MB # Duplicated
max-inbound-metadata-size: 1MB # Duplicated### Current WorkaroundUse GrpcChannelBuilderCustomizer bean to apply settings globally:
@Bean
GrpcChannelBuilderCustomizer<?> globalCustomizer() {
return (name, builder) -> builder
.maxInboundMetadataSize(1024 * 1024)
.maxInboundMessageSize(5 * 1024 * 1024);
} // This works but requires code instead of configuration.Proposed Solution
Named channels should merge/inherit from default-channel:
public ChannelConfig getChannel(String name) {
if ("default".equals(name)) {
return this.defaultChannel;
}
ChannelConfig channel = this.channels.get(name);
if (channel != null) {
return this.defaultChannel.mergeWith(channel); // Merge with defaults
}
channel = this.defaultChannel.copy();
// ..
}PR: #347
This would be consistent with how other Spring Boot configurations handle inheritance/defaults.
mateusz-zajac-datarobot, Svitlana-Zmiivska and najibulloShapoatov
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request