Logging Reactor Flows
Get introduced to logging Reactor flows.
We'll cover the following...
Debugging after the fact isn’t our only tool in Reactor. It’s possible to log actions as they happen.
Getting data reactively
When we sit down to insert some log.debug()
statements into our Reactor code we might find that it’s suddenly not so easy.
This isn’t precisely the fault of Reactive Streams’ asynchronous nature, but instead Project Reactor’s application of functional programming techniques. By using lambda functions and method references, we just don’t have as many places to insert those convenient log.debug()
statements.
For example, Java 8 programming lets us write code like this:
Mono<Double> findPriceByMethodReference(String id) {// tag::method-handle[]return itemRepository.findById(id).map(Item::getPrice);// end::method-handle[]}
Reactor’s .map()
operator transforms the retrieved Item
into a price
using Item::getPrice
.
With the wide adoption of Java 8, it’s not uncommon to find code like this all over ...