@@ -61,7 +61,7 @@ final class GrpcClients(system: ExtendedActorSystem) extends Extension {
6161 private val log = LoggerFactory .getLogger(classOf [GrpcClients ])
6262
6363 @ volatile private var proxyHostname : Option [String ] = None
64- @ volatile private var selfPort : Option [Int ] = None
64+ @ volatile private var proxyPort : Option [Int ] = None
6565 @ volatile private var identificationInfo : Option [IdentificationInfo ] = None
6666 private implicit val ec : ExecutionContext = system.dispatcher
6767 private val clients = new ConcurrentHashMap [Key , AnyRef ]()
@@ -84,15 +84,14 @@ final class GrpcClients(system: ExtendedActorSystem) extends Extension {
8484 identificationInfo = info
8585 }
8686
87- def setSelfServicePort (port : Int ): Unit = {
87+ def setProxyPort (port : Int ): Unit = {
8888 log.debug(" Setting port to: [{}]" , port)
89- selfPort = Some (port)
89+ proxyPort = Some (port)
9090 }
9191
9292 def getComponentGrpcClient [T ](serviceClass : Class [T ]): T = {
93- getLocalGrpcClient (serviceClass)
93+ getProxyGrpcClient (serviceClass)
9494 }
95-
9695 def getProxyGrpcClient [T ](serviceClass : Class [T ]): T = {
9796 getLocalGrpcClient(serviceClass)
9897 }
@@ -104,13 +103,22 @@ final class GrpcClients(system: ExtendedActorSystem) extends Extension {
104103 def getGrpcClient [T ](serviceClass : Class [T ], service : String ): T =
105104 getGrpcClient(serviceClass, service, port = 80 , remoteAddHeader)
106105
107- /** Local gRPC clients point to services (user components or Kalix services) in the same deployable */
106+ /** gRPC clients point to services (user components or Kalix services) in the same deployable */
108107 private def getLocalGrpcClient [T ](serviceClass : Class [T ]): T = {
109- proxyHostname match {
110- case Some (" localhost" ) => getGrpcClient(serviceClass, " localhost" , selfPort.getOrElse(9000 ), localAddHeader)
111- case Some (selfName) => getGrpcClient(serviceClass, selfName, 80 , localAddHeader)
112- case None =>
113- throw new IllegalStateException (" Self service name not set by proxy at discovery, too old proxy version?" )
108+ (proxyHostname, proxyPort) match {
109+ case (Some (internalProxyHostname), Some (port)) =>
110+ getGrpcClient(serviceClass, internalProxyHostname, port, localAddHeader)
111+ // for backward compatibiliy with proxy 1.0.14 or older.
112+ case (Some (" localhost" ), None ) =>
113+ log.warn(" you are using an old version of the Kalix proxy" )
114+ getGrpcClient(serviceClass, " localhost" , proxyPort.getOrElse(9000 ), localAddHeader)
115+ // for backward compatibiliy with proxy 1.0.14 or older
116+ case (Some (proxyHostname), None ) =>
117+ log.warn(" you are using an old version of the Kalix proxy" )
118+ getGrpcClient(serviceClass, proxyHostname, 80 , localAddHeader)
119+ case _ =>
120+ throw new IllegalStateException (
121+ " Service proxy hostname and port are not set by proxy at discovery, too old proxy version?" )
114122 }
115123 }
116124
0 commit comments