I want to execute 3 calls simultaneously and process the results once they're all done.
I know this can be achieved using AsyncRestTemplate as it is mentioned here How to use AsyncRestTemplate to make multiple calls simultaneously?
However, AsyncRestTemplate is deprecated in favor of WebClient. I have to use Spring MVC in the project but interested if I can use a WebClient just to execute simultaneous calls. Can someone advise how this should be done properly with WebClient?
Another way:
Assuming a WebClient wrapper (like in reference doc):
..., you could invoke it asynchronously via:
[2] [3]
Thanks, Welcome & Kind Regards,
You can use Spring reactive client
WebClient
to send parallel requests. In this example,Here:
getUserInfo
makes an HTTP call to get user info from another service and returnsMono
getOrgInfo
method makes HTTP call to get organization info from another service and returnsMono
Mono.zip()
waits all the results from all monos and merges into a new mono and returns it.Then, call
getOrgUserInfo().block()
to get the final result.You can make HTTP calls concurrently using simple
RestTemplate
andExecutorService
:Or