66import io .grpc .ManagedChannel ;
77import io .grpc .ManagedChannelBuilder ;
88import java .util .Map ;
9+ import java .util .Objects ;
910import java .util .concurrent .ConcurrentHashMap ;
1011import java .util .concurrent .TimeUnit ;
1112import org .slf4j .Logger ;
@@ -21,36 +22,50 @@ public class GrpcChannelRegistry {
2122 */
2223 @ Deprecated
2324 public ManagedChannel forAddress (String host , int port ) {
24- return this .forPlaintextAddress (host , port );
25+ return this .forPlaintextAddress (host , port , GrpcChannelConfig . builder (). build () );
2526 }
2627
2728 public ManagedChannel forSecureAddress (String host , int port ) {
29+ return forSecureAddress (host , port , GrpcChannelConfig .builder ().build ());
30+ }
31+
32+ public ManagedChannel forSecureAddress (String host , int port , GrpcChannelConfig config ) {
2833 assert !this .isShutdown ;
29- String channelId = this .getChannelId (host , port , false );
34+ String channelId = this .getChannelId (host , port , false , config );
3035 return this .channelMap .computeIfAbsent (
31- channelId , unused -> this .buildNewChannel (host , port , false ));
36+ channelId , unused -> this .buildNewChannel (host , port , false , config ));
3237 }
3338
3439 public ManagedChannel forPlaintextAddress (String host , int port ) {
40+ return forPlaintextAddress (host , port , GrpcChannelConfig .builder ().build ());
41+ }
42+
43+ public ManagedChannel forPlaintextAddress (String host , int port , GrpcChannelConfig config ) {
3544 assert !this .isShutdown ;
36- String channelId = this .getChannelId (host , port , true );
45+ String channelId = this .getChannelId (host , port , true , config );
3746 return this .channelMap .computeIfAbsent (
38- channelId , unused -> this .buildNewChannel (host , port , true ));
47+ channelId , unused -> this .buildNewChannel (host , port , true , config ));
3948 }
4049
41- private ManagedChannel buildNewChannel (String host , int port , boolean isPlaintext ) {
42- LOG .info ("Creating new channel {}" , this .getChannelId (host , port , isPlaintext ));
50+ private ManagedChannel buildNewChannel (
51+ String host , int port , boolean isPlaintext , GrpcChannelConfig config ) {
52+ LOG .info ("Creating new channel {}" , this .getChannelId (host , port , isPlaintext , config ));
4353
4454 ManagedChannelBuilder <?> builder = ManagedChannelBuilder .forAddress (host , port );
4555 if (isPlaintext ) {
4656 builder .usePlaintext ();
4757 }
58+
59+ if (config .getMaxInboundMessageSize () != null ) {
60+ builder .maxInboundMessageSize (config .getMaxInboundMessageSize ());
61+ }
4862 return builder .build ();
4963 }
5064
51- private String getChannelId (String host , int port , boolean isPlaintext ) {
65+ private String getChannelId (
66+ String host , int port , boolean isPlaintext , GrpcChannelConfig config ) {
5267 String securePrefix = isPlaintext ? "plaintext" : "secure" ;
53- return securePrefix + ":" + host + ":" + port ;
68+ return securePrefix + ":" + host + ":" + port + ":" + Objects . hash ( config ) ;
5469 }
5570
5671 /**
0 commit comments