I am calling a post endpoint that returns a Void. I am trying to get the time elapsed.
It seems it is not calling an endpoint. doOnSuccess is also not getting called.
public void createTask(CreateTaskDTO task) {
client
.post()
.uri(path)
.body(BodyInserters.fromValue(task))
.exchangeToMono(response -> response.bodyToMono(Void.class))
.elapsed()
.doOnSuccess(
tuple -> {
Status.incrementTaskCreationCount(task.getLoginIds().size());
Status.incrementWriteCount();
log.info(
"time taken by the ServiceImpl createTask=[{}] for {}",
tuple.getT1(),
task);
})
.map(Tuple2::getT2)
.subscribe();
}
Advertisement
Answer
elapsed() measures the time between when the Mono is subscribed to and the moment the Mono emits an item. But, Mono<Void> response doesn’t emit any value.
You can use thenReturn to continue the sequence:
.exchangeToMono(response -> response.bodyToMono(Void.class)) .thenReturn(true) .elapsed()