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 ...