This library provides retry capabilites based on the runtime attributes as well as provides custom retry handling based on the response.
Retry Config can be passed along with ClientHttpRequest
webClient.syncHttpResponse(
ClientHttpRequest.<Map, Map>builder()
.url("https:abc.com/v1/create")
.httpMethod(HttpMethod.POST)
.requestHeaders(new HttpHeaders())
.request(body)
.clientRetryConfig()
.build())
Attribute | Description | Default |
---|---|---|
maxAttempts | Maximum number of reties | 0 |
backOff | Backoff time between retries in seconds | 0 |
Custom retry handlers can be added, which would get invoked after exhaution of all reties specified in Client Retry Config.
- Implement custom retry handler. RetryHandler
- Populate the Retry handler factory at the application start event.
@Component
@AllArgsConstructor
public class ApplicationEventListener {
private final List<RetryHandler> RetryHandler;
@EventListener
public void handleContextRefresh(ContextRefreshedEvent event) {
// Init Retry Handler Factory
RetryHandler.forEach(
handler -> RetryHandlerFactory.addHandler(handler.getName(), handler));
}
}
- Pass the list fo handlers to be called in the ClientHttpRequest.
webClient.syncHttpResponse(
ClientHttpRequest.<Map, Map>builder()
.url("https:abc.com/v1/create")
.httpMethod(HttpMethod.POST)
.requestHeaders(new HttpHeaders())
.request(body)
.retryHandlers()
.build())