首页 文章

Lagom服务如何使用其他服务?

提问于
浏览
2

在三个案例中我无法思考 .

  • Lagom服务在同一个集群中使用另一个Lagom服务

  • Lagom服务在另一个集群中使用另一个Lagom服务

  • Lagom服务使用外部非Lagom服务

  • 外部非Lagom服务使用Lagom服务

1. Lagom service consumes another Lagom service in the same cluster

对于这种情况,方法是ServiceAImpl依赖于ServiceB 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那个

群集应仅跨越运行相同服务的节点 .

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

  • "The same service"表示其API公开给外部服务的顶级服务?

  • 在Lagom 1 Microservice = 1服务中使用外部API n内部服务?

2. Lagom service consumes another Lagom service in a different cluster

文档says

请注意,如果您要与之通信的服务实际上是Lagom服务,您可能需要阅读文档以与外部Lagom项目集成 .

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

3. Lagom service consumes an external non-Lagom service

您首先要做的是在服务定位器中注册每个外部服务 . 假设我们要注册一个名为weather的外部服务,该服务在http:// localhost:3333上运行,这里是我们要添加到build:lagomUnmanagedServices in ThisBuild:= Map(“weather” - >“http:// localhost :3333" )

与该IP的 Contract 是什么?它背后应该是什么?

4. An external non-Lagom service consumes a Lagom service

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

1 回答

  • 1

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

    Lagom服务调用以相当直接的方式映射到惯用的REST . 因此,在与外部服务交谈时,该IP上的内容应该是REST服务 . 同样,当外部服务与Lagom交谈时,它应该使用REST .

相关问题