Use spring cloud gateway to merge results from two microservices

razenha :

Suppose I have two microservices, payment and company. I have an endpoint /payments/late that returns a list of late payments:

[{'id': 1, due_date: 2019-05-05, value: 1234.123, company_id: 5}]

And I want to create a table on my front end app that shows a table like this?

Payments:

Company Name | Due Date        | Amount
    XXX      | 05/05/2018      | 1234.12

So my front end app would have to make two web services call from two different microservices.

I'm thinking about adding an API gateway label that would be responsible for:

a) calling the payments webservice. b) getting the ids from the payments webservice return and calling the company webservice to get the companies data. c) merging the companies data with the payments data in a single json:

[{'id': 1, due_date: 2019-05-05, value: 1234.123, company_id: 5, company_name: "XXXXX"}]

or something similar.

Is it possible to do that using Spring Cloud Gateway?

Sneh Saluja :

You could call your Company Webservice from Payments Webservice using Feign Client and then merge the results in Payments Webservice and return it to the UI.

From UI, call /payments/late and get the merged result.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=132155&siteId=1