Is there an analog of AsyncContext in spring mvc? (How to write an HTTP response in another thread)

I have google about spring support for the servlet specification 3.0 / 3.1 and most of the information I found in this article: Understanding Callable and spring DeferredResult

Here the author says that you can return Callable or DefferedResult from the controller and say that the servlet 3.0 / 3.1 is supported in spring.

But I do not understand how to apply it in my situation:

I have an external system, and I get the result from this system asynchronously.

In the controller, I write something like this:

 externalSystenm.send(requestId, message); 

and I have another thread where I get the result:

 Message m = externalSystem.get(); m.getRequestId();// According this id I can map message to request 

I know that in the servlet API I can save asyncContext on the map and then found it.

How can I recognize it in spring?

+5
source share
1 answer

I found the following article: Spring MVC 3.2 Preview: Introducing Servlet 3, Async Support

Example:

 @RequestMapping("/quotes") @ResponseBody public DeferredResult<String> quotes() { DeferredResult<String> deferredResult = new DeferredResult<String>(); // Add deferredResult to a Queue or a Map... return deferredResult; } // In some other thread... <-- important phrase deferredResult.setResult(data); // Remove deferredResult from the Queue or Map 
+3
source

Source: https://habr.com/ru/post/1266406/


All Articles