无法将基于非 lagom 的静态项目服务与 service-locator-dns 库一起使用

unable to use non lagom based static project services with service-locator-dns library

我们在 Lagom 中成功集成 'service-locator-dns' 并部署在 Kubernetes 中,Lagom 项目中的所有服务都正确解析了 Kubernetes SRV 请求。

但即使是静态定义的(在build.sbt中)非lagom项目也会经历name-translatorssrv-translators并最终无法解析。

我在 Github https://github.com/lightbend/service-locator-dns/issues/29

中提出了同样的问题

我们能否通过更改名称翻译器本身来避免这种情况,或者我们是否需要进行任何额外的更改?

如果您提供支持或参考任何文档,这将对我们非常有帮助。

登录kubernetes

日志

Resolving: premium-calculator
Translated premium-calculator to _http-lagom-api._tcp.premium-calculator.staging.svc.cluster.local
Resolving _http-lagom-api._tcp.premium-calculator.staging.svc.cluster.local (SRV)
Message to /10.114.0.10:53: Message(16,<QUERY,RD,SUCCESS>,List(Question(_http-lagom-api._tcp.premium-calculator.staging.svc.cluster.local,SRV,IN)),List(),List(),List())
Received message from /10.114.0.10:53: ByteString(0, 16, -127, -125, 0, 1, 0, 0, 0, 1, 0, 0, 15, 95, 104, 116, 116, 112, 45, 108, 97, 103, 111, 109, 45, 97, 112, 105, 4, 95, 116, 99, 112, 18, 112, 114, 101, 109, 105, 117, 109, 45, 99, 97, 108, 99, 117, 108, 97, 116, 111, 114, 7, 115, 116, 97, 103, 105, 110, 103, 3, 115, 118, 99, 7, 99, 108, 117, 115, 116, 101, 114, 5, 108, 111, 99, 97, 108, 0, 0, 33, 0, 1, 7, 99, 108, 117, 115, 116, 101, 114, 5, 108, 111, 99, 97, 108, 0, 0, 6)... and [76] more
Decoded: Message(16,<AN,QUERY,RD,RA,NAME_ERROR>,Vector(Question(_http-lagom-api._tcp.premium-calculator.staging.svc.cluster.local,SRV,IN)),Vector(),Vector(UnknownRecord(cluster.local,60,6,1,ByteString(2, 110, 115, 3, 100, 110, 115, 7, 99, 108, 117, 115, 116, 101, 114, 5, 108, 111, 99, 97, 108, 0, 10, 104, 111, 115, 116, 109, 97, 115, 116, 101, 114, 7, 99, 108, 117, 115, 116, 101, 114, 5, 108, 111, 99, 97, 108, 0, 90, -80, -107, 80, 0, 0, 112, -128, 0, 0, 28, 32, 0, 9, 58, -128, 0, 0, 0, 60))),Vector())
Resolved: Vector()
java.lang.IllegalStateException: Service premium-calculator was not found by service locator

服务特质

trait PremiumCalculator extends Service {
  def getPremiums(channelName: String): ServiceCall[JsValue, JsValue]
  override final def descriptor = {
    import Service._
    named("premium-calculator")
      .withCalls(
        restCall(Method.POST, "/api/v2/premium/:channelName", getPremiums _))
      .withAutoAcl(true)
  }
}

在build.sbt

lagomUnmanagedServices in ThisBuild := Map(
  "premium-calculator" -> "https://test.in",
)

要在 Kubernetes 上的 Lagom 中定位 Non-Lagom/Third 派对服务,我们必须使用 Lagom 的服务定位器。像这样:

lagom.services {
  "premium-calculator" = "https://test.in"
}

此外,我们必须使用 ConfigurationServiceLocator 来定位服务:

if(environment.isProd()) {
  bind(ServiceLocator.class).to(ConfigurationServiceLocator.class);
}

此处ConfigurationServiceLocator通过配置定位服务(顾名思义)。

希望对您有所帮助!