Data Aggregation in an API Gateway - Zuul

I am looking for a solution that would provide data aggregation in the Gateway API. I am using spring cloud netflix zuul for API gateway. I created 3 microservices using spring boot -

Catalog - All products DeviceInfo - a particular product detail Inventory - product stock 

Here's the 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 

On the product details 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 a way to make one call to an API gateway that combines the results above the two calls? Both calls give a JSON response.

+5
source share
1 answer

You can use the aggregator-microservice template, but not in ZUUL. Keep Zuul as a stateless gate. A microservice aggregator 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 browse https://github.com/iluwatar/java-design-patterns/tree/master/aggregator-microservices

0
source

All Articles