'How to asynchronously make micro service calls and map back to response object in Spring WebClient?
I’m fairly new to reactive programming in Spring. In my application I need to make a DB call and then make 3 micro service calls to enrich the original data.
Once the DB call is complete, I can make all three requests in parallel. Each call works individually, but I’m confused on how to run the 3 API calls in parallel and stitch it all back to a Response Object.
OriginalData mainData = someDao.getAppData();
Mono<ReferenceData1> data1 = SomeClient.getData1(mainData);
Flux<ReferenceData2> data2 = SomeClient.getData2(mainData);
Flux<ReferenceData3> data3 = SomeClient.getData3(mainData);
// do some processing of the data
// zip all 4 objects together in a response object
I’ve been able to zip 2 fluxes back in a Flux object, but my goal here would be to return a Mono Response object that is made up of these 4 objects.
Any ideas on how to make this work, or any better suggestions are appreciated!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
