Interface Retry


public interface Retry
Factories for common configurations.

Apply these factories after setting the wait interval. The factories that heed the Retry-After header decorate the builder's IntervalBiFunction. RetryConfig.Builder.waitDuration(Duration) and RetryConfig.Builder.intervalFunction(io.github.resilience4j.core.IntervalFunction) replace that function rather than composing with it, so calling either one afterwards discards the Retry-After support without warning: the retry then waits the configured interval and ignores the header. Other builder methods, including RetryConfig.Builder.maxAttempts(int), are unaffected and may be called in any order.

// Correct - wait interval first, factory last
RetryConfig.Builder<HttpServletResponse> builder = RetryConfig.custom();
builder.maxAttempts(3).waitDuration(Duration.ofSeconds(5));
Retry.idempotent(Duration.ofSeconds(30)).accept(builder);

// Wrong - waitDuration() discards the Retry-After support installed above
Retry.idempotent(Duration.ofSeconds(30)).accept(builder);
builder.waitDuration(Duration.ofSeconds(5));   // header now silently ignored
  • Method Summary

    Static Methods
    Modifier and Type
    Method
    Description
    static Consumer<io.github.resilience4j.retry.RetryConfig.Builder<jakarta.servlet.http.HttpServletResponse>>
    idempotent(int... retry)
    Adds a Predicate that decides whether to retry based on the HTTP status code in the response.
    static Consumer<io.github.resilience4j.retry.RetryConfig.Builder<jakarta.servlet.http.HttpServletResponse>>
    idempotent(Duration limit, int... retry)
    Adds a Predicate that decides whether to retry based on the HTTP status code in the response and whether any {code Retry-After} header allows for a retry within an acceptable interval, and adds an IntervalBiFunction to extend the wait interval as needed.
    static Consumer<io.github.resilience4j.retry.RetryConfig.Builder<jakarta.servlet.http.HttpServletResponse>>
    nonIdempotent(int... retry)
    Adds a Predicate that decides whether to retry based on the HTTP status code in the response.
    static Consumer<io.github.resilience4j.retry.RetryConfig.Builder<jakarta.servlet.http.HttpServletResponse>>
    nonIdempotent(Duration limit, int... retry)
    Adds a Predicate that decides whether to retry based on the HTTP status code in the response and whether any {code Retry-After} header allows for a retry within an acceptable interval, and adds an IntervalBiFunction to extend the wait interval as needed.
    static Consumer<io.github.resilience4j.retry.RetryConfig.Builder<jakarta.servlet.http.HttpServletResponse>>
    onlyCodes(int... retry)
    Adds a Predicate that decides whether to retry based on the HTTP status code in the response.
    static Consumer<io.github.resilience4j.retry.RetryConfig.Builder<jakarta.servlet.http.HttpServletResponse>>
    onlyCodes(Duration limit, int... retry)
    Adds a Predicate that decides whether to retry based on the HTTP status code in the response and whether any {code Retry-After} header allows for a retry within an acceptable interval, and adds an IntervalBiFunction to extend the wait interval as needed.
    static Consumer<io.github.resilience4j.retry.RetryConfig.Builder<jakarta.servlet.http.HttpServletResponse>>
    Adds an IntervalBiFunction that respects any Retry-After header provided in the response, without limit.
    static Consumer<io.github.resilience4j.retry.RetryConfig.Builder<jakarta.servlet.http.HttpServletResponse>>
    Adds an IntervalBiFunction that respects any Retry-After header provided in the response, and adds a predicate to ensure the wait does not exceed the limit.
  • Method Details

    • idempotent

      static Consumer<io.github.resilience4j.retry.RetryConfig.Builder<jakarta.servlet.http.HttpServletResponse>> idempotent(int... retry)
      Adds a Predicate that decides whether to retry based on the HTTP status code in the response.
      Parameters:
      retry - status codes that allow retry, in addition to the defaults for idempotent functions provided by RetryStatusCodes
      Returns:
      consumer that uses HTTP status code for retry decisions.
    • nonIdempotent

      static Consumer<io.github.resilience4j.retry.RetryConfig.Builder<jakarta.servlet.http.HttpServletResponse>> nonIdempotent(int... retry)
      Adds a Predicate that decides whether to retry based on the HTTP status code in the response.
      Parameters:
      retry - status codes that allow retry, in addition to the defaults for non-idempotent functions provided by RetryStatusCodes
      Returns:
      consumer that uses HTTP status code for retry decisions.
    • onlyCodes

      static Consumer<io.github.resilience4j.retry.RetryConfig.Builder<jakarta.servlet.http.HttpServletResponse>> onlyCodes(int... retry)
      Adds a Predicate that decides whether to retry based on the HTTP status code in the response.
      Parameters:
      retry - complete list of status codes that allow retry
      Returns:
      consumer that uses HTTP status code for retry decisions.
    • idempotent

      static Consumer<io.github.resilience4j.retry.RetryConfig.Builder<jakarta.servlet.http.HttpServletResponse>> idempotent(Duration limit, int... retry)
      Adds a Predicate that decides whether to retry based on the HTTP status code in the response and whether any {code Retry-After} header allows for a retry within an acceptable interval, and adds an IntervalBiFunction to extend the wait interval as needed.
      Parameters:
      limit - the maximum wait interval that will be allowed by a Retry-After.
      retry - status codes that allow retry, in addition to the defaults for idempotent functions provided by RetryStatusCodes
      Returns:
      consumer that uses HTTP status code and Retry-After for retry decisions and waits.
      API Note:
      Apply after RetryConfig.Builder.waitDuration(Duration); see the class documentation for why order matters.
    • nonIdempotent

      static Consumer<io.github.resilience4j.retry.RetryConfig.Builder<jakarta.servlet.http.HttpServletResponse>> nonIdempotent(Duration limit, int... retry)
      Adds a Predicate that decides whether to retry based on the HTTP status code in the response and whether any {code Retry-After} header allows for a retry within an acceptable interval, and adds an IntervalBiFunction to extend the wait interval as needed.
      Parameters:
      limit - the maximum wait interval that will be allowed by a Retry-After.
      retry - status codes that allow retry, in addition to the defaults for non-idempotent functions provided by RetryStatusCodes
      Returns:
      consumer that uses HTTP status code and Retry-After for retry decisions and waits.
      API Note:
      Apply after RetryConfig.Builder.waitDuration(Duration); see the class documentation for why order matters.
    • onlyCodes

      static Consumer<io.github.resilience4j.retry.RetryConfig.Builder<jakarta.servlet.http.HttpServletResponse>> onlyCodes(Duration limit, int... retry)
      Adds a Predicate that decides whether to retry based on the HTTP status code in the response and whether any {code Retry-After} header allows for a retry within an acceptable interval, and adds an IntervalBiFunction to extend the wait interval as needed.
      Parameters:
      limit - the maximum wait interval that will be allowed by a Retry-After.
      retry - complete list of status codes that allow retry
      Returns:
      consumer that uses HTTP status code and Retry-After for retry decisions and waits.
      API Note:
      Apply after RetryConfig.Builder.waitDuration(Duration); see the class documentation for why order matters.
    • retryAfter

      static Consumer<io.github.resilience4j.retry.RetryConfig.Builder<jakarta.servlet.http.HttpServletResponse>> retryAfter()
      Adds an IntervalBiFunction that respects any Retry-After header provided in the response, without limit.

      CAUTION: The response may specify a Retry-After interval years in the future. Skew between the local system clock and the clock on the service that generated the header also may produce unexpectedly long wait durations. A delay too large to express is clamped to RetryAfterParser.MAX_DELAY, so without a limit a single hostile or misconfigured response can park a retry effectively forever. Implementations that do not set a limit alternatively can defend against an unacceptable wait interval using e.g. a TimeLimiter to terminate excessive waits and a Bulkhead to prevent too many outstanding requests.

      Returns:
      consumer that uses Retry-After for retry waits.
      API Note:
      Apply after RetryConfig.Builder.waitDuration(Duration); see the class documentation for why order matters.
    • retryAfter

      static Consumer<io.github.resilience4j.retry.RetryConfig.Builder<jakarta.servlet.http.HttpServletResponse>> retryAfter(Duration limit)
      Adds an IntervalBiFunction that respects any Retry-After header provided in the response, and adds a predicate to ensure the wait does not exceed the limit.
      Parameters:
      limit - the longest the client should wait.
      Returns:
      consumer that uses Retry-After for retry decisions and waits.
      API Note:
      Apply after RetryConfig.Builder.waitDuration(Duration); see the class documentation for why order matters.