Mono

Creating a Mono is very simple. The following Mono emits one element after a delay of 5 seconds.

   Mono<String> stubMonoWithADelay =    Mono.just("Ranga").delayElement(Duration.ofSeconds(5));

We want to listen to the events from Mono and log them to the console. We can do that using the statement specified here:

    stubMonoWithADelay.subscribe(System.out::println);

However, if you run the program with the two preceding statements in a Test annotation as shown in the following code, you would see that nothing is printed to the console:

    @Test    public void monoExample() throws InterruptedException {      Mono<String> stubMonoWithADelay =         Mono.just("Ranga").delayElement(Duration.ofSeconds(5));      stubMonoWithADelay.subscribe(System.out::println); } ...

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.