The retry event handler

Operations can time out or fail because of broken connections, network glitches, unavailability of upstream services. Client applications deal with these failures by implementing retries. The retry is a very simple pattern where failed requests are retried a configurable number of times in case of a failure before the operation is marked as a failure.

You can provide a custom global RetryConfig. In order to create a custom global RetryConfig, you can use the RetryConfig builder.

Parameter Default value Description
type retry The configuration property type
name GW_RETRY The name of the retry instance that is used for logging purposes
maxAttempts 3 The maximum number of retry attempts
backoff Configures custom backoff algorithm for handling retries of failed network calls.
  • type
The type is random or exponential.
  • In random exponential backoff the clients wait random interval between consecutive retries. Typically the wait interval is calculated using the following formula:
    wait_interval = base * multiplier^n
  • With the exponential backoff the clients wait progressively longer intervals between consecutive retries. In this algorithm the wait interval is calculated using the following formula:
    wait_interval = (base * 2^n) +/- (random_interval)
  • base is the initial interval, for example wait for the first retry
  • n is the number of failures that have occurred
  • interval
500 ms The base backoff period that is set in milliseconds.
  • multiplier
1.5 The multiplier is an arbitrary multiplier that can be replaced with any suitable value for backoff period. The value is in Double format.
  • randomizationFactor
0.5 The randomization factor. The value is in Double format.
retryOnExceptionPredicateClass throwable -> true Configures a Predicate that evaluates if an exception has to be retried. The Predicate must return true, if the exception has to be retried, otherwise it must return false. To invoke retry when specified exceptions occurred
retryOnResultPredicateClass result -> false Configures a Predicate that evaluates if a result has to be retried. The Predicate must return true, if the result has to be retried, otherwise it must return false. Used to invoke retry when the specified results are received.
intervalFunctionClass numOfAttempts -> waitDuration A class that extends IntervalFunction. This functional is used to modify the waiting interval after a failure. By default the wait duration remains constant.