Provide Response to user who call the RestApi without waiting for the microservice rest call using spring boot

1.1k Views Asked by At

I am developing a web API for an application. I had got a situation where the user will send a few data to my API. After processing the data I have to forward a few data to other API.

But I don't want to concentrate on the response from the second API to where I had called.

After calling the second API I want to send my response to the user without waiting for the second API response. Can anyone tell me how to handle this situation?

My API is written in JAVA spring boot REST, The Second API to where am calling is in PYTHON.

1

There are 1 best solutions below

0
On

@Async will make it execute in a separate thread, i.e. the caller will not wait for the completion of the called method.

Limitations

  • it must be applied to public methods only
  • self-invocation – calling the async method from within the same class – won’t work

Example: Spring Doc, Example 1, Example 2