Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get response time of web client web-flux

Just want to know if there is any way to get the response time of web client of spring web-flux?

like image 512
Trần Minh Phương Avatar asked Mar 10 '19 08:03

Trần Minh Phương


Video Answer


1 Answers

you also have the possibility to use elapsed() for this kind of thing

webClient.get().uri("/bla").retrieve()
     .bodyToMono(String.class)
     .elapsed()  // map the stream's time into our streams data
     .doOnNext(tuple -> log.info("Milliseconds for retrieving {}", tuple.getT1()))
     .map(Tuple2::getT2) // after outputting the measurement, return the data only

Note, that elapsed() elapses the whole reactive stream, so if you're doing something before the webClient... part, you should put an elapsed() before that - this resets the timer.

like image 193
Frischling Avatar answered Oct 06 '22 04:10

Frischling