Building subscribers to Flux and Mono

Reactor Flux and Mono provide a wide choice of subscribe methods. Reactive publishers raise four types of events, namely subscription, value, completion, and error. Individual functions can be registered for each of the events. We can also register a subscriber without listening to any kind of event. Let's look at all of the possible variants offered, as follows:

fibonacciGenerator.subscribe(); (1)fibonacciGenerator.subscribe(t -> System.out.println("consuming " + t));   (2)fibonacciGenerator.subscribe(t -> System.out.println("consuming " + t),                e -> e.printStackTrace() ); (3)fibonacciGenerator.subscribe(t -> System.out.println("consuming " + t),                e -> e.printStackTrace(), ()-> System.out.println("Finished")); ...

Get Hands-On Reactive Programming with Reactor now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.