
Resiliencia — resilience patterns for Java 21
five patterns · one fluent api · zero core dependencies
Retry, Timeout, CircuitBreaker, Bulkhead and RateLimiter for Java 21+. Built on virtual threads and composed with an explicit order the library validates for you — no reflection, no magic, nothing to configure twice.
- jdk 21+
- 0 deps · core / patterns / compose
- 5 patterns
- virtual threads
patterns
Five ways to fail on purpose
Each one implements Resilient — call(), callAsync(), or outcome() if you'd rather not deal with exceptions at all.
Retry
Retries a failing call with a configurable number of attempts, wait duration, and optional exponential backoff.
Timeout
Cancels a call that runs too long. Real cancellation via virtual thread interruption — not polling.
CircuitBreaker
Stops calling a degraded dependency. Closed, Open, HalfOpen — modeled as a sealed CircuitState.
Bulkhead
Caps concurrent calls with a semaphore. Blocking a virtual thread while it waits is cheap.
RateLimiter
Caps how often a call may run inside a configurable time window.
composition
Chain them with Policy
Policy.compose(...).and(...) builds an explicit call chain. The order is checked at construction time — not every combination makes sense.
var policy = Policy.compose(circuitBreaker)
.and(retry)
.and(timeout);
policy.call(() -> api.fetchOrder(id));Retry wrapping a CircuitBreaker throws InvalidPolicyException at construction — there's no legitimate use case for retrying past an open circuit.
guides
Written for the way you'll actually use it
Short, practical guides, not a full API reference.
01
Getting started
Add resiliencia-core and resiliencia-patterns, then wrap your first call in a Retry.
02
Composing a Policy
Chain CircuitBreaker, Retry and Timeout with an order the library validates for you.
03
Testing with ManualClock
Drive retries and timeouts deterministically with resiliencia-test — no Thread.sleep in your test suite.
04
Metrics with Micrometer
Wire pattern and Policy events into Micrometer counters, gauges and timers.
javadoc
One module at a time
Each module ships its own Javadoc jar — no monolithic API surface to wade through.
| module | what's in it | external deps |
|---|---|---|
| resiliencia-core | Resilient, Outcome<T>, exception hierarchy, SPI | none |
| resiliencia-patterns | Retry, Timeout, CircuitBreaker, Bulkhead, RateLimiter | none |
| resiliencia-compose | Policy — fluent, validated composition | none |
| resiliencia-metrics | ResilienciaMetrics abstraction | none |
| resiliencia-micrometer | ResilienciaMetrics over Micrometer's MeterRegistry | Micrometer |
| resiliencia-test | Fakes, ManualClock, JUnit 5 assertions | JUnit 5 |
| resiliencia-spring (coming soon) | Auto-config, @WithRetry, @WithCircuitBreaker | Spring Boot |
↳ published from each module's javadoc:jar to Maven Central. This site also hosts a combined, aggregated copy, rebuilt by CI on every push to main.
open the aggregated javadoc →