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 14, 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( "learning-spring-boot", "comments.new", comment)) ...