October 2018
Intermediate to advanced
556 pages
15h 18m
English
In reactive streams, we may easily add a custom monitoring logic even without built-in support. For example, the following code explains how to add an invocation counter for a WebClient that does not have any default instrumentation:
WebClient.create(serviceUri) // (1) .get() .exchange() .flatMap(cr -> cr.toEntity(User.class)) // (2) .doOnTerminate(() -> registry .counter("user.request", "uri", serviceUri) // (3) .increment())
Here, we create a new WebClient for a target serviceUri (1), make a request and deserialize the response to a User entity (2). When the operation is terminated, we manually increase the counter with a custom tag uri where the value represents serviceUri (3).
Similarly, we may combine ...