【发布时间】:2016-04-12 19:15:41
【问题描述】:
我想不出三种情况。
- Lagom 服务使用同一集群中的另一个 Lagom 服务
- Lagom 服务使用不同集群中的另一个 Lagom 服务
- Lagom 服务使用外部非 Lagom 服务
- 外部非 Lagom 服务使用 Lagom 服务
1. Lagom 服务使用同一集群中的另一个 Lagom 服务
对于这种情况,方法是 ServiceAImpl 依赖于 ServiceB API,该 API 绑定到将被注入到 ServiceAImpl 的具体实现。
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);
}
}
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