I'm looking for a solution that would provide kind of data Aggregation in API Gateway. I am using spring cloud netflix zuul for API gateway. I created 3 micro services using spring boot -
Catalog - All products
DeviceInfo - a particular product detail
Inventory - product stock
Here is Zuul configuration -
zuul.routes.deviceInfo.path=/device/deviceInfo/**
zuul.routes.deviceInfo.url=http://localhost:9002/getDeviceInfo
zuul.routes.catalog.path=/device/all/**
zuul.routes.catalog.url=http://localhost:9001/getProductCatalog
zuul.routes.inventory.path=/device/stock/**
zuul.routes.inventory.url=http://localhost:9003/getInventory
ribbon.eureka.enabled=false
server.port=8080
In product detail page I need to make two calls -
http://localhost:8080/device/deviceInfo/ - for product details
http://localhost:8080/device/stock/ - for stock details
Is there any way to make a single call to API gateway which will combine the results of above two calls? Both calls are giving JSON in response.
Gateway Aggregation pattern is similar with Gateway Routing but extra it is offering aggregation of services. Basically Gateway Aggregation pattern offers to use a gateway service that provide to aggregate multiple internal requests to internal microservices with exposing a single request to the client.
Zuul is built on servlet 2.5 (works with 3. x), using blocking APIs. It doesn't support any long lived connections, like websockets. Gateway is built on Spring Framework 5, Project Reactor and Spring Boot 2 using non-blocking APIs.
It handles all the requests and performs the dynamic routing of microservice applications. It works as a front door for all the requests. It is also known as Edge Server. Zuul is built to enable dynamic routing, monitoring, resiliency, and security.
Also a single point of failure for Zuul is not of much concern as you can use multiple instances of Zuul(may be 2) and load balance them, that solve your problem for single point of failure.
You may use aggregator-microservices pattern but not in ZUUL. Keep Zuul as stateless gateway. Aggregator microservice should have client code like this
public String getProductTitle() {
String response = null;
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
HttpGet httpGet = new HttpGet("http://localhost:51515/information");
try (CloseableHttpResponse httpResponse = httpClient.execute(httpGet)) {
response = EntityUtils.toString(httpResponse.getEntity());
}
} catch (IOException e) {
LOGGER.error("Exception caught.", e);
}
return response;
}
}
Please have look at https://github.com/iluwatar/java-design-patterns/tree/master/aggregator-microservices
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With