Applying backpressure to Mono<T> and Flux<T>
Retrieving elements from array
or Collection
is different from data retrieval in Mono<T>
or Flux<T>
. In a typical data retrieval operation, the control of data emission depends on whether subscribers will pull it or not. The process can be very fast when a number of elements is practically manageable but dangerously slow when data abruptly increases. Once the subscriber or receiver becomes overwhelmed with the volume of data emission, some parts of the application may starve and will lead to memory leak. Backpressure is the process of controlling the flow of the data Stream to avoid an overflow of data emission between fast Publisher<T>
and slow Subscriber<T>
. It aims to maintain an optimal performance of any Reactive events even in worst-case scenarios.
Getting ready
Here, we will use Maven project ch08
and add the code for backpressure.
How to do it...
Date emissions in Streams are affected by the backpressure...