1
votes

I would like to know is there, or can we make use of any functionality to log the actual time taken by a function returning Mono/Flux? For example something like creating a @Timed annotation to log the actual time taken by it. I know the function return type being Flux/Mono, so it should return immediately so that is why I wanna know if we can actually do something like this so that we can know which modules/sub-modules are taking how much time?

We want to migrate our blocking spring-boot service to spring webflux, so going through all the possible options we have for better understanding.

P.S. I am new To reactive programming, still learning the paradigm.

1

1 Answers

2
votes

You can use metrics() operator to time a publisher. You can combine this with the name() and tags() operators to customise the metrics that get published.

listenToEvents()
   .name("events") 
   .tag("source", "kafka")
   .metrics() 
   .doOnNext(event -> log.info("Received {}", event))
   .delayUntil(this::processEvent)
   .subscribe();

Publisher metrics docs