API网关(Zuul)合并两个微服务响应

问题描述 投票:0回答:1

我有两个微服务,用户微服务和订单微服务。

用户微服务返回用户详细信息和订单微服务返回用户的订单详细信息。

http://localhost:8080/microservice1/getuser

{ “ID”: “100”, “名称”: “测试”}

http://localhost:8081/microservice2/getorders

{ “参数userid”: “100”, “订单”:{ “订单ID”: “5001”, “产品名”: “mobilephone”}}

我使用Spring cloud Zuul作为API网关,它将请求路由到每个微服务。

http://localhost:9090/api/microservice1/getuser

http://localhost:9090/api/microservice2/getorders

现在从UI,我需要调用两个端点

是他们以任何方式合并微服务的响应,如{“id”:“100”,“name”:“test”,“orders”:{“orderid”:“5001”,“productname”:“mobilephone” “}}

所以客户端只需要调用一个端点http://localhost:9090/api/getdetail

我们如何在API网关级别实现这一目标?

java spring spring-boot microservices api-gateway
1个回答
1
投票

Zuul不应该用于聚合响应,您可以创建编排微服务服务,并在内部使用restTemplate获取所有响应并根据需要进行聚合。

保持Zuul无国籍,网关不应该有任何逻辑或有状态。

© www.soinside.com 2019 - 2024. All rights reserved.