【问题标题】:How Lagom services consume other services?Lagom 服务如何消耗其他服务?
【发布时间】:2016-04-12 19:15:41
【问题描述】:

我想不出三种情况。

  1. Lagom 服务使用同一集群中的另一个 Lagom 服务
  2. Lagom 服务使用不同集群中的另一个 Lagom 服务
  3. Lagom 服务使用外部非 Lagom 服务
  4. 外部非 Lagom 服务使用 Lagom 服务

1. Lagom 服务使用同一集群中的另一个 Lagom 服务

对于这种情况,方法是 ServiceAImpl 依赖于 ServiceB API,该 API 绑定到将被注入到 ServiceAImpl 的具体实现。

ServiceB binding:

import com.google.inject.AbstractModule;
import com.lightbend.lagom.javadsl.server.ServiceGuiceSupport;
import docs.services.HelloService;

public class Module extends AbstractModule implements ServiceGuiceSupport {

    protected void configure() {
        bindClient(HelloService.class);
    }
}

ServiceA implementation:

public class MyServiceImpl implements MyService {
  private final HelloService helloService;

  @Inject
  public MyServiceImpl(HelloService helloService) {
    this.helloService = helloService;
  }

  @Override
  public ServiceCall<NotUsed, NotUsed, String> sayHelloLagom() {
    return (id, msg) -> {
      CompletionStage<String> response = helloService.sayHello().invoke("Lagom");
      return response.thenApply(answer ->
          "Hello service said: " + answer
      );
    };
  }
}

如果我理解正确的话,为了以这种方式使用服务 API,两个客户端必须在同一个集群中。 但是Lagom says那个

一个集群应该只跨越运行相同服务的节点。

在这种情况下,我们有两种不同类型的服务。

  • “相同的服务”是指 API 暴露给外部服务的顶级服务?
  • 在 Lagom 1 微服务中 = 1 个带有外部 API 的服务 + n 个内部服务?

2。 Lagom 服务使用不同集群中的另一个 Lagom 服务

文档says

请注意,如果您要与之通信的服务实际上是 Lagom 服务,您可能需要阅读integrating with an external Lagom projects 的文档。

为什么只配置了对服务API的依赖,而没有配置外部Lagom服务的IP和端口?

3. Lagom 服务使用外部非 Lagom 服务

您要做的第一件事是注册每个外部 服务定位器中的服务。假设我们要注册一个外部 在 http://localhost:3333 上运行的名为 weather 的服务,这里 是我们要添加到构建中的内容:

 lagomUnmanagedServices in ThisBuild := Map("weather" -> "http://localhost:3333")

与该 IP 的合同是什么?背后应该是什么?

4.外部非 Lagom 服务使用 Lagom 服务

我必须使用Third-Party Registration Pattern,直到Lagom 支持self registration pattern

【问题讨论】:

  • 我发现你的问题,太令人困惑了......
  • 同意许多高级 Lagom 文档讨论解耦服务,而部署传达了 1 个集群的简单性......

标签: microservices service-discovery lagom


【解决方案1】:

当 Lagom 谈到“集群”时,它指的是 Akka 集群。每个服务都可以部署为一个 Akka 集群,即一个服务可以是一个节点集群。所以你在一个集群中没有多个服务,你只有一个集群服务。

Lagom 服务调用以一种相当直接的方式映射到惯用的 REST。因此,在与外部服务通信时,该 IP 上的东西应该是 REST 服务。同样,当外部服务与 Lagom 通信时,它应该使用 REST。

【讨论】:

  • 感谢@James 的回答。第(1)点的情况下,HelloService不是和MyServiceImpl在同一个集群中运行的吗?
猜你喜欢
  • 2013-09-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-26
  • 2021-01-03
相关资源
最近更新 更多