简体   繁体   English

Spring Cloud Zuul用于复合API调用?

[英]Spring Cloud Zuul for composite API calls?

I am starting to build a Microservice API Gateway, and I am using Spring Cloud Zuul to help me with the routing. 我开始构建微服务API网关,并且正在使用Spring Cloud Zuul来帮助我进行路由。 But some calls to the Gateway API will need multiple requests to different services. 但是,对Gateway API的某些调用将需要对不同服务的多个请求。

Lets say I have 2 services: Order Details Service and Delivery Service. 可以说我有两项服务:订单详细信息服务和送货服务。 I want to have a Gateway endpoint GET /orders/{orderId} that makes a call to Order Details service and then Delivery Service and combine the two to return full Order details with delivery. 我希望有一个网关端点GET / orders / {orderId},该端点先调用Order Details服务,然后再调用Delivery Service,然后将两者结合起来以返回完整的订单详细信息。 Is this possible with the routing of Zuul(maybe filters?) or should I make these by hand(create a controller specifically for these kinds of requests) using something like RestTemplate to make the calls? Zuul(可能是过滤器?)的路由是否可行?还是我应该使用RestTemplate之类的东西手动进行处理(专门为这类请求创建一个控制器)?

You can avoid that complication and forward request from your Gateway to the Order service to make an order, than make HTTP request from Order service to Delivery service to make the delivery. 您可以避免这种复杂性,而避免从GatewayOrder service转发请求以进行订单,而不是从Order serviceDelivery service进行HTTP请求以进行递送。 By nature those entities work like that. 从本质上说,这些实体就是这样工作的。 And don't worry about the speed, it is extremely fast. 不用担心速度,它非常快。

That is in a first place, in your case, if you want to get the order details, with delivery details, that should go in the same manner. 在您的情况下,如果要获取订单明细和交货明细,那应该放在首位,应该采用相同的方式。 Maybe even your order service should persist some of delivery details in its database. 甚至您的订单服务都应该在其数据库中保留一些交货详细信息。 We were doing it like that, you should avoid redundant data, but sometimes it make sense. 我们这样做是为了避免冗余数据,但有时这样做是有道理的。

Here is the chart of making the order: 这是下订单的图表: 在此处输入图片说明

Make sense? 说得通?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM