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

时间:2016-04-12 19:15:41

标签: microservices service-discovery lagom

我不能在三种情况下思考。

  1. Lagom服务在同一群集中使用另一个Lagom服务
  2. Lagom服务消耗另一个群集中的另一个Lagom服务
  3. Lagom服务消耗外部非Lagom服务
  4. 外部非Lagom服务使用Lagom服务
  5. 1。 Lagom服务在同一个集群中使用另一个Lagom服务

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

      

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

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

    • &#34;相同的服务&#34;是指其API向外部服务公开的顶级服务?
    • 在Lagom 1 Microservice = 1服务中使用外部API + n内部服务?

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

    文档says

      

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

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

    第3。 Lagom服务消耗外部非Lagom服务

      

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

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

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

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

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

1 个答案:

答案 0 :(得分:2)

当Lagom谈论&#34; cluster&#34;时,它指的是Akka集群。每个服务可以部署为Akka集群,即,服务可以是节点集群。因此,您在集群中没有多个服务,只需要一个集群服务。

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

相关问题