I'd like to use Micrometer to record the execution time of an async method when it eventually happens. Is there a recommended way to do this?
Example: Kafka Replying Template. I want to record the time it takes to actually execute the sendAndReceive call (sends a message on a request topic and receives a response on a reply topic).
public Mono<String> sendRequest(Mono<String> request) {
return request
.map(r -> new ProducerRecord<String, String>(requestsTopic, r))
.map(pr -> {
pr.headers()
.add(new RecordHeader(KafkaHeaders.REPLY_TOPIC,
"reply-topic".getBytes()));
return pr;
})
.map(pr -> replyingKafkaTemplate.sendAndReceive(pr))
... // further maps, filters, etc.
Something like
responseGenerationTimer.record(() -> replyingKafkaTemplate.sendAndReceive(pr)))
won't work here; it just records the time that it takes to create the Supplier
, not the actual execution time.
recordCallable()
? – Murchison