Class RetryConfig
This class provides configuration options for HTTP client retry behavior when making requests. It allows customization of the maximum number of retry attempts, exponential backoff settings, jitter for backoff times, and connection/socket timeouts.
The default configuration is 0 retry attempts (no retries), with exponential backoff starting at 1000ms and multiplying by 2.0 for each retry. Jitter is enabled by default with a factor of 0.5 to prevent synchronized retry storms.
This configuration is used internally by HttpClientProvider.getHttpClient()
to create HTTP clients with server-wide retry capabilities. The configuration
is set globally through the HTTP client provider SPI configuration.
Server-wide SPI properties for configuring retry behavior:
spi-connections-http-client-default-max-retries- Maximum number of retry attempts (default: 0)spi-connections-http-client-default-initial-backoff-millis- Initial backoff time in milliseconds (default: 1000)spi-connections-http-client-default-backoff-multiplier- Multiplier for exponential backoff (default: 2.0)spi-connections-http-client-default-jitter-factor- Random jitter factor to apply to backoff times (default: 0.5)spi-connections-http-client-default-use-jitter- Whether to apply jitter to backoff times (default: true)
Example configuration:
spi-connections-http-client-default-max-retries=3 spi-connections-http-client-default-initial-backoff-millis=1000 spi-connections-http-client-default-backoff-multiplier=2.0This configuration applies to all outgoing HTTP requests from Keycloak, including OCSP validation, identity provider communication, and other external HTTP calls.
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionbooleanCompares this RetryConfig with another object for equality.doubleGets the multiplier used for exponential backoff between retry attempts.intGets the connection timeout in milliseconds.longGets the initial backoff time in milliseconds before the first retry attempt.doubleGets the jitter factor to apply to backoff times.intGets the maximum number of retry attempts.intGets the socket timeout in milliseconds.inthashCode()Returns a hash code value for this RetryConfig.booleanDetermines whether to apply jitter to backoff times.
-
Method Details
-
getMaxRetries
public int getMaxRetries()Gets the maximum number of retry attempts.- Returns:
- The maximum number of retry attempts
-
getInitialBackoffMillis
public long getInitialBackoffMillis()Gets the initial backoff time in milliseconds before the first retry attempt.- Returns:
- The initial backoff time in milliseconds
-
getBackoffMultiplier
public double getBackoffMultiplier()Gets the multiplier used for exponential backoff between retry attempts.- Returns:
- The backoff multiplier
-
getConnectionTimeoutMillis
public int getConnectionTimeoutMillis()Gets the connection timeout in milliseconds.- Returns:
- The connection timeout in milliseconds
-
getSocketTimeoutMillis
public int getSocketTimeoutMillis()Gets the socket timeout in milliseconds.- Returns:
- The socket timeout in milliseconds
-
isUseJitter
public boolean isUseJitter()Determines whether to apply jitter to backoff times.Jitter adds randomness to backoff times to prevent synchronized retry storms when multiple clients are retrying at the same time.
- Returns:
trueif jitter should be applied,falseotherwise
-
getJitterFactor
public double getJitterFactor()Gets the jitter factor to apply to backoff times.The jitter factor determines how much randomness to apply to the backoff time. A value of 0.5 means the actual backoff time will be between 50% and 150% of the calculated exponential backoff time.
- Returns:
- The jitter factor
-
equals
Compares this RetryConfig with another object for equality.Two RetryConfig objects are considered equal if all their configuration parameters match exactly.
-
hashCode
public int hashCode()Returns a hash code value for this RetryConfig.This method is implemented to be consistent with
equals(Object), ensuring that equal RetryConfig objects have the same hash code.
-