Reputation: 3023
I am currently migrating our existing Spring asynchronous REST architecture to Spring's new WebFlux library and have a question around joining multiple requests so that they can listen for the same published response.
Use Case is as follows:
How can Client B subscribe to the same response stream that Client A is waiting for?
Upvotes: 4
Views: 3538
Reputation: 13515
"Client A has subscribed and waits for a response"
I suppose the request is coded as a Mono
and client A sibscribes to it literally:
Subscriber<Response> clientA = ...
Mono<Response> request = makeRequest(...);
request.subscribe(clientA);
then clientB should subscribe the same way:
Subscriber<Response> clientB = ...
request.subscribe(clientB);
Moreover, the cache should contain not the previously saved response data, but the requests themselves, of type Mono<Response>
. Then, if such a request is found in the cache, new clients simply subscribe to it, regardless of was that request already completed or not.
Upvotes: 8