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

Constructors

Link copied to clipboard
constructor()

Functions

Link copied to clipboard
fun bulkhead(config: BulkheadConfig.() -> Unit)

Configures a bulkhead. Limits the number of concurrent executions and optional waiting queue.

Link copied to clipboard
fun bulkheadNamed(registry: BulkheadRegistry, name: String, config: BulkheadConfig.() -> Unit)

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.

Link copied to clipboard
fun cache(config: CacheConfig.() -> Unit)

Configures an in-memory cache. Results are cached by key and TTL; cache is checked before executing the block.

Link copied to clipboard
fun chaos(block: ChaosConfig.() -> Unit)

Configures the chaos policy for fault injection.

Link copied to clipboard

Configures a circuit breaker. Execution is rejected when the circuit is open.

Link copied to clipboard

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.

Link copied to clipboard
fun coalesce(config: CoalesceConfig.() -> Unit)

Configures request coalescing.

Link copied to clipboard

Configures the order in which policies are composed. Policies are applied from outermost (first in list) to innermost (last in list).

Link copied to clipboard
fun fallback(config: FallbackConfig<Any?>)

Configures a fallback policy. When the block fails (excluding cancellation), FallbackConfig.onFallback is invoked.

Link copied to clipboard
fun hedging(config: HedgingConfig.() -> Unit)

Configures a hedging policy. Multiple parallel attempts are launched; the first success is returned.

Link copied to clipboard

Configures a rate limiter. Execution may be delayed or rejected when the rate limit is exceeded.

Link copied to clipboard
fun rateLimiterNamed(registry: RateLimiterRegistry, name: String, configure: RateLimiterConfig.() -> Unit)

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.

Link copied to clipboard
fun retry(config: RetryPolicyConfig.() -> Unit)

Configures a retry policy. The block will be retried on failure according to RetryPolicyConfig.

Link copied to clipboard
fun timeout(config: TimeoutConfig.() -> Unit)

Configures a timeout policy. Execution is cancelled if it exceeds the configured duration.