Skip to content

Latest commit

 

History

History
61 lines (48 loc) · 2.04 KB

RetryHandling.md

File metadata and controls

61 lines (48 loc) · 2.04 KB

Retry Handling

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())

Client Retry Config

WebClientRetryConfig

Attribute Description Default
maxAttempts Maximum number of reties 0
backOff Backoff time between retries in seconds 0

Custom Retry Handlers

Custom retry handlers can be added, which would get invoked after exhaution of all reties specified in Client Retry Config.

Steps

  1. Implement custom retry handler. RetryHandler
  2. 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));
  }
}
  1. 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())