简体   繁体   中英

Java + Micrometer @Timed annotation + Spring reactive @Repository possible?

Small question on the @Timed annotation from Micrometer, and how to use it with a reactive @Repository from Spring please.

I have a @Repository interface which is very straightforward, not even custom queries.

@Repository
public interface MyRepository extends ReactiveCassandraRepository<MyPojo, String> {

Here the example is with reactive Cassandra, but any reactive repository will do.

I would like to time the execution of the default methods, the save, findById, findAll, basically, all the straightforward methods a @Repository offers.

By time, I mean the real time taken to insert the data or to retrieve the data.

(This is particularly useful to see the read and write performance over time, under high load, etc...)

Hence, I tried with great hope:

@Repository
@Timed("mysupertimer")
public interface MyRepository extends ReactiveCassandraRepository<MyPojo, String> {

But sadly, it is not working. Just to avoid confusion, it is not working for the repository methods. I have @Timed in my @Controller layer, and different places of @Service layer, I see all the other metrics fine.

Also, I am really hoping for an answer on annotating the @Repository please. I understand I can just @Timed "all the places in my project calling the repository", but I have 300 calls to repositories and will need to explain to any future contributor to also annotate his calls.

A solution directly on the @Repository layer would be amazing.

Many thanks!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM