The request-stream model lets a client send one request and receive a stream of zero or more values. RSocket represents the request with Mono and the response with Flux, supporting asynchronous, nonblocking reactive communication. section 14.1
A Spring implementation follows this shape:
- Define a value object for each streamed result, such as a stock quote containing a symbol, price, and timestamp. section 14.2.2
- Map a route such as stock/{symbol} with @MessageMapping and capture the symbol using @DestinationVariable. section 14.2.2
- Return Flux<StockQuote>; Spring interprets the Flux as a request-stream interaction. Create values periodically with Flux.interval and map each interval to a result. section 14.2.2
- On the client, route the request through RSocketRequester, call retrieveFlux rather than retrieveMono, subscribe, and process each value. section 14.2.2
Streaming stock quotes
A client requests the price for XYZ once, then receives a new randomly generated StockQuote every second. This avoids repeatedly polling for the current price. section 14.2.2
Visualizes the single request followed by a stream of response values. section 14.1
