ResilientBuilder
A DSL builder for creating and configuring a composition of resilience policies.
This builder is used within the resilient { ... } block to define which resilience strategies to apply to a given operation. Each method corresponds to a specific policy and accepts a lambda with a receiver to configure it.
Example of usage:
val policy = resilient {
retry {
maxAttempts = 3
}
timeout {
duration = 5.seconds
}
circuitBreaker {
failureRateThreshold = 50.0
}
}The policies are composed in a specific, predefined order to ensure predictable behavior. See the resilient function documentation for the exact composition order.
See also
Functions
Configures a bulkhead. Limits the number of concurrent executions and optional waiting queue.
Uses a shared DefaultBulkhead from registry keyed by name. Multiple policies can pass the same BulkheadRegistry and name to enforce a global limit across those policies.
Configures an in-memory cache. Results are cached by key and TTL; cache is checked before executing the block.
Configures the chaos policy for fault injection.
Configures a circuit breaker. Execution is rejected when the circuit is open.
Uses a shared DefaultCircuitBreaker from registry keyed by name. Multiple policies can pass the same CircuitBreakerRegistry and name to share a global circuit breaker state across those policies.
Configures request coalescing.
Configures the order in which policies are composed. Policies are applied from outermost (first in list) to innermost (last in list).
Configures a fallback policy. When the block fails (excluding cancellation), FallbackConfig.onFallback is invoked.
Configures a hedging policy. Multiple parallel attempts are launched; the first success is returned.
Configures a rate limiter. Execution may be delayed or rejected when the rate limit is exceeded.
Uses a shared DefaultRateLimiter from registry keyed by name. Multiple policies can pass the same RateLimiterRegistry and name to enforce a global quota across those policies.
Configures a retry policy. The block will be retried on failure according to RetryPolicyConfig.
Configures a timeout policy. Execution is cancelled if it exceeds the configured duration.