From 2edf768cd6dde78a8399df26ad831c2e1ebbeddf Mon Sep 17 00:00:00 2001 From: tangjiafu Date: Sun, 14 Apr 2024 13:56:56 +0800 Subject: [PATCH] replace nameResolverFactory with NameResolverRegistry --- .../grpc/internal/NettyClientUtils.scala | 23 ++++++++----------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/runtime/src/main/scala/org/apache/pekko/grpc/internal/NettyClientUtils.scala b/runtime/src/main/scala/org/apache/pekko/grpc/internal/NettyClientUtils.scala index 8a9c3f24..e8317bcc 100644 --- a/runtime/src/main/scala/org/apache/pekko/grpc/internal/NettyClientUtils.scala +++ b/runtime/src/main/scala/org/apache/pekko/grpc/internal/NettyClientUtils.scala @@ -14,7 +14,6 @@ package org.apache.pekko.grpc.internal import java.util.concurrent.TimeUnit - import javax.net.ssl.SSLContext import org.apache.pekko import pekko.{ Done, NotUsed } @@ -22,13 +21,12 @@ import pekko.annotation.InternalApi import pekko.event.LoggingAdapter import pekko.grpc.{ GrpcClientSettings, GrpcResponseMetadata, GrpcSingleResponse } import pekko.stream.scaladsl.{ Flow, Keep, Source } -import io.grpc.{ CallOptions, MethodDescriptor } +import io.grpc.{ CallOptions, MethodDescriptor, NameResolverRegistry } import io.grpc.netty.shaded.io.grpc.netty.GrpcSslContexts import io.grpc.netty.shaded.io.grpc.netty.NegotiationType import io.grpc.netty.shaded.io.grpc.netty.NettyChannelBuilder import io.grpc.netty.shaded.io.netty.handler.ssl.{ SslContext, SslContextBuilder } -import scala.annotation.nowarn import scala.concurrent.duration.FiniteDuration import scala.concurrent.{ ExecutionContext, Future, Promise } import scala.util.{ Failure, Success } @@ -46,22 +44,21 @@ object NettyClientUtils { def createChannel(settings: GrpcClientSettings, log: LoggingAdapter)( implicit ec: ExecutionContext): InternalChannel = { - @nowarn("cat=deprecation") var builder = NettyChannelBuilder // Not sure why netty wants to be able to shoe-horn the target into a URI... but ok, // we follow their lead and encode the service name as the 'authority' of the URI. .forTarget("//" + settings.serviceName) .flowControlWindow(NettyChannelBuilder.DEFAULT_FLOW_CONTROL_WINDOW) - // TODO avoid nameResolverFactory #1092, then 'nowarn' can be removed above - .nameResolverFactory( - new PekkoDiscoveryNameResolverProvider( - settings.serviceDiscovery, - settings.defaultPort, - settings.serviceName, - settings.servicePortName, - settings.serviceProtocol, - settings.resolveTimeout)) + + NameResolverRegistry.getDefaultRegistry.register( + new PekkoDiscoveryNameResolverProvider( + settings.serviceDiscovery, + settings.defaultPort, + settings.serviceName, + settings.servicePortName, + settings.serviceProtocol, + settings.resolveTimeout)) if (!settings.useTls) builder = builder.usePlaintext()