diff --git a/build.gradle b/build.gradle index af7717e04..f5f14bdab 100644 --- a/build.gradle +++ b/build.gradle @@ -26,7 +26,7 @@ apply plugin: 'io.codearte.nexus-staging' project.version = "1.35.2-SNAPSHOT" // {x-version-update:gax:current} ext { - grpcVersion = '1.16.1' + grpcVersion = '1.17.1' commonProtosVersion = '1.12.0' authVersion = '0.12.0' // Project names not used for release @@ -116,6 +116,7 @@ subprojects { grpcAuth: "io.grpc:grpc-auth:${grpcVersion}", grpcProtobuf: "io.grpc:grpc-protobuf:${grpcVersion}", grpcNetty: "io.grpc:grpc-netty-shaded:${grpcVersion}", + grpcAlts: "io.grpc:grpc-alts:${grpcVersion}", gson: "com.google.code.gson:gson:2.7", guava: 'com.google.guava:guava:26.0-android', jsr305: 'com.google.code.findbugs:jsr305:3.0.2', diff --git a/gax-grpc/build.gradle b/gax-grpc/build.gradle index b9915e240..0dc04d7fe 100644 --- a/gax-grpc/build.gradle +++ b/gax-grpc/build.gradle @@ -15,7 +15,8 @@ dependencies { libraries.authCredentials, libraries.commonProtos, libraries.apiCommon, - libraries.grpcNetty + libraries.grpcNetty, + libraries.grpcAlts compileOnly libraries.autovalue diff --git a/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java b/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java index 65d201d71..9360f825c 100644 --- a/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java +++ b/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java @@ -41,8 +41,8 @@ import com.google.common.collect.ImmutableList; import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; +import io.grpc.alts.GoogleDefaultChannelBuilder; import java.io.IOException; -import java.lang.reflect.InvocationTargetException; import java.util.Map; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; @@ -184,49 +184,16 @@ private ManagedChannel createSingleChannel() throws IOException { int port = Integer.parseInt(endpoint.substring(colon + 1)); String serviceAddress = endpoint.substring(0, colon); - // TODO(hzyi): Change to ManagedChannelBuilder directly when - // https://github.com/grpc/grpc-java/issues/4050 is resolved. - ManagedChannelBuilder builder; + ManagedChannelBuilder builder = + GoogleDefaultChannelBuilder.forAddress(serviceAddress, port) + .intercept(headerInterceptor) + .intercept(metadataHandlerInterceptor) + .userAgent(headerInterceptor.getUserAgentHeader()) + .executor(executor); + if (maxInboundMetadataSize != null) { - Class nettyChannelBuilderClass; - try { - nettyChannelBuilderClass = - Class.forName("io.grpc.netty.shaded.io.grpc.netty.NettyChannelBuilder"); - } catch (ClassNotFoundException e) { - try { - nettyChannelBuilderClass = Class.forName("io.grpc.netty.NettyChannelBuilder"); - } catch (ClassNotFoundException ex) { - throw new RuntimeException( - "Unable to create the channel because neither" - + " \"io.grpc.netty.NettyChannelBuilder\" nor" - + " \"io.grpc.netty.shaded.io.grpc.netty.NettyChannelBuilder\" is found."); - } - } - try { - Object object = - nettyChannelBuilderClass - .getMethod("forAddress", String.class, int.class) - .invoke(null, serviceAddress, port); - object = - nettyChannelBuilderClass - .getMethod("maxHeaderListSize", int.class) - .invoke(object, maxInboundMetadataSize); - builder = (ManagedChannelBuilder) object; - } catch (NoSuchMethodException - | IllegalAccessException - | IllegalArgumentException - | InvocationTargetException e) { - throw new RuntimeException( - "Unable to set maxHeaderListSize due to exception: " + e.getMessage()); - } - } else { - builder = ManagedChannelBuilder.forAddress(serviceAddress, port); + builder.maxInboundMetadataSize(maxInboundMetadataSize); } - builder - .intercept(headerInterceptor) - .intercept(metadataHandlerInterceptor) - .userAgent(headerInterceptor.getUserAgentHeader()) - .executor(executor); if (maxInboundMessageSize != null) { builder.maxInboundMessageSize(maxInboundMessageSize); }