Adding customized metrics to track message flow

Having added the ability to comment on other people's posted images, it would be nice to start gathering metrics.

To do so, we can introduce metrics similar to those shown in Chapter 5, Developer Tools for Spring Boot Apps, as follows:

    @Controller 
    public class CommentController { 
 
      private final RabbitTemplate rabbitTemplate; 
 
      private final MeterRegistry meterRegistry; 
 
      public CommentController(RabbitTemplate rabbitTemplate, 
       MeterRegistry meterRegistry) { 
         this.rabbitTemplate = rabbitTemplate; 
         this.meterRegistry = meterRegistry; } @PostMapping("/comments") public Mono<String> addComment(Mono<Comment> newComment) { return newComment.flatMap(comment -> Mono.fromRunnable(() -> rabbitTemplate .convertAndSend( ...

Get Learning Spring Boot 2.0 - Second Edition 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.