Affects: org.springframework:spring-webflux:6.0.1
I'm trying out the new feature HTTP interface provided by Spring6, which I think is very interesting.
I want to know how to retry when an exception occurs in the request. The defaultStatusHandler()
method in the Builder
can only handle HTTP responses, but it seems that it cannot handle exceptions.
Comment From: rstoyanchev
There is nothing special required in WebClient
. Reactor provides this. For example:
interface MyHttpService {
@GetExchange("/greeting")
Mono<String> getGreeting();
}
MyHttpService service = ... ;
// retry 3 times
String greeting = service.getGreeting().retryWhen(Retry.max(3)).block();
// retry 3 times with "jitter" (varied pauses)
String greeting = service.getGreeting().retryWhen(Retry.backoff(3, Duration.ofMillis(100))).block();