简体   繁体   中英

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. But some calls to the Gateway API will need multiple requests to different services.

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. 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?

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. 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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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