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