Skip to Content
Hands-On Reactive Programming in Spring 5
book

Hands-On Reactive Programming in Spring 5

by Oleh Dokuka, Igor Lozynskyi
October 2018
Intermediate to advanced
556 pages
15h 18m
English
Packt Publishing
Content preview from Hands-On Reactive Programming in Spring 5

Adding custom Micrometer meters

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

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Spring Microservices in Action, Second Edition

Spring Microservices in Action, Second Edition

John Carnell, Illary Huaylupo Sanchez

Publisher Resources

ISBN: 9781787284951Supplemental Content