Reputation: 37034
I have google about spring support of servlet 3.0/3.1 specification and most of information I have found at this article: Understanding Callable and Spring DeferredResult
Here author say that you can return Callable
or DefferedResult
from controller and say it is servlet 3.0/3.1 maintain in spring.
But I don't understand how to apply it in my situation:
I have external system and I get result from this system asynchrounously.
In controller I write something like this:
externalSystenm.send(requestId, message);
and I have another thread where I get result:
Message m = externalSystem.get();
m.getRequestId();// According this id I can map message to request
I know that in servlet API I allow to save asyncContext in map and then found it.
How can I acheve it in spring ?
Upvotes: 4
Views: 1236
Reputation: 37034
I have found 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
Upvotes: 3