Reputation: 151
My application is simple 3-tier Spring Boot rest web-service with usual synchronous endpoints. But since the period of getting response from downstream system where my service sends requests is quite long (kind of 60 seconds), I need to add support of asynchronous REST calls to my service to save upstream systems from a response awaiting. In other words, if a response to a downstream system is going to take more than 60 seconds (timeout), then the upstream system break the connection with my service and keeps its doing...
But when the response come, my service using "reply-to" header from the upstream system will send the response to the upstream system.
All the things above are kind of call back or webhook.
But I didn't find any examples of implementation.
How to implement this mechanism? How can I find more information? Does Spring Boot have something to implement it out-of-box?
Thank you for attention!
Upvotes: 2
Views: 2138
Reputation: 1450
You can use the @Async annotation from Spring. You will also need to enable in your application this by setting @EnableAsync.
An important note is that your method with the @Async annotation should be on a different class from where it is being called. This will let the Spring proxy intercept the call and effectively do it asynchronous.
Please find here the official tutorial.
Upvotes: 4