Mono<T> is a Reactive Streams
Publisher, also augmented with a lot of operators that
can be used to generate, transform, orchestrate Mono sequences.
It is a specialization of
Flux that can emit at most 1
<T> element: a Mono is either
valued (complete with element), empty (complete without element) or failed (error).
Mono<Void> can be used in cases where only the completion signal is interesting (the
Reactive Streams equivalent of a
Runnable task completing).
Flux, the operators can be used to define an asynchronous pipeline which will be
materialized anew for each
Note that some API that change the sequence's cardinality will return a
Flux (and vice-versa,
APIs that reduce the cardinality to 1 in a
Flux return a
See the javadoc here.
Mono in action:
Mono.just(1) .map(integer -> "foo" + integer) .or(Mono.delay(Duration.ofMillis(100))) .subscribe(System.out::println);
As for the Flux let's return a empty
Mono using the static factory.
static <T> Mono<T> empty() // Create a Mono that completes without emitting any item.
Now, we will try to create a
Mono which never emits anything.
empty(), it won't even emit an
Flux, you can create a
Mono from an available (unique) value.
And exactly as we did for the flux, we can propagate exceptions.