Batching stream elements

Project Reactor supports the batching of stream elements (Flux<T>) in a couple of ways:

  • Buffering elements into containers such as List, the result stream has the Flux<List<T>>type.
  • Windowing elements into a stream of streams such as Flux<Flux<T>>. Note that, now, the stream signals not values but sub-streams, which we can process.
  • Grouping elements by some key into a stream that has the type Flux<GroupedFlux<K, T>>. Each new key triggers a new GroupedFlux instance and all elements with that key are pushed through that instance of the GroupFlux class.

Buffering and windowing may happen based on the following:

  • The number of processed elements; let's say every 10 elements
  • Some time-span; let's say every 5 minutes ...

Get Hands-On Reactive Programming in Spring 5 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.