Flux

Flux represents a reactive stream emitting 0 to n elements. The following snippet shows a simple Flux example:

    @Test    public void simpleFluxStream() {      Flux<String> stubFluxStream = Flux.just("Jane", "Joe");      stubFluxStream.subscribe(new SystemOutConsumer());      }

A couple of important things to note are as follows:

  • Flux<String> stubFluxStream = Flux.just("Jane", "Joe"): We are creating a Flux using the Flux.just method. It can create simple streams with hardcoded elements.
  • stubFluxStream.subscribe(new SystemOutConsumer()): We are registering an instance of SystemOutConsumer as a subscriber on Flux.

The output is shown in the following screenshot:

The following snippet shows a more complex example of a Flux with two subscribers:

 private ...

Get Mastering Spring 5.0 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.