We discussed life cycle hooks in Chapter 2, The Publisher and Subscriber APIs in a Reactor. These can be used to configure callbacks for every life cycle event. Reactor provides the life cycle error callback hook to configure the error handler. The doOnError hook allows us to consume an error and perform the intended function. If we have configured the doOnError hook along with the error callback, then both will be invoked simultaneously by Reactor. The following code shows this:
@Test public void testDoError() { // Removed for brevity fibonacciGenerator .doOnError(System.out::println) .subscribe(System.out::println, e -> e.printStackTrace()); }
The preceding code does the following:
- Configures the println function in ...