我有两个微服务,用户微服务和订购微服务。
用户微服务返回用户的详细信息,订单微服务返回用户的订购详细信息。
http:// localhost:8080 / microservice1 / getuser
{“ id”:“ 100”,“名称”:“ test”}
http:// localhost:8081 / microservice2 / getorders
{“ userid”:“ 100”,“ orders”:{“ orderid”:“ 5001”,“ productname”:“ mobilephone”}}
我正在使用Spring cloud Zuul作为API网关,它将请求路由到每个微服务。
http:// localhost:9090 / api / microservice1 / getuser
http:// localhost:9090 / api / microservice2 / getorders
现在从用户界面,我需要调用两个端点
是他们将{{id“:” 100“,” name“:” test“,” orders“:{” orderid“:” 5001“,” productname“:” mobile“之类的两种微服务的响应进行合并的任何方式吗“}}
这样客户端只需调用一个端点http:// localhost:9090 / api / getdetail
我们如何在API网关级别实现这一目标?
Zuul不应用于聚合响应,您可以创建业务流程微服务服务,并在内部使用restTemplate根据需要获取所有响应和聚合。
保持Zuul为无状态,网关不应具有任何逻辑或有状态。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句