https://github.com/vyag/sakura-retry
An elegant JVM library for transient failure handling.
https://github.com/vyag/sakura-retry
error-handling failsafe java kotlin kotlin-library retry retry-library retry-strategies
Last synced: about 2 months ago
JSON representation
An elegant JVM library for transient failure handling.
- Host: GitHub
- URL: https://github.com/vyag/sakura-retry
- Owner: vyag
- License: apache-2.0
- Created: 2020-01-22T14:31:55.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2025-08-04T15:53:49.000Z (2 months ago)
- Last Synced: 2025-08-04T19:28:30.915Z (2 months ago)
- Topics: error-handling, failsafe, java, kotlin, kotlin-library, retry, retry-library, retry-strategies
- Language: Kotlin
- Homepage:
- Size: 371 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://maven-badges.herokuapp.com/maven-central/com.github.marks-yag/sakura-retry)

[](https://github.com/vyag/sakura-retry/actions/workflows/maven.yml)[中文](README_cn.md) | English
# Sakura Retry
An elegant(useless😉) and lightweight retry framework for JVM which supports:
- Highly customizable retry and backoff policies.
- Both synchronous and asynchronous execution.
- Apply pre-defined retry template on existing object using dynamic proxy.*Sakura Retry* does **NOT** attempt to support more features than other mainstream retry frameworks, nor does it offer better performance. In the early years, I started writing *Sakura Retry* due to a lack of information, and I have kept using it because I like it more and more in terms of aesthetics.
# Getting Started
Available on [Maven Central](https://mvnrepository.com/artifact/com.github.marks-yag/sakura-retry).
**Example:**
```kotlin
fun main() {
val retry = Retry.Builder()
.setCondition(maxAttempts(3))
.setBackoffPolicy(fixedDelayInSeconds(10) + randomDelayInSeconds(0, 1))
.addFailureListener(logging())
.build()
retry.call {
println("maybe fail")
}
}
```**Basic Concepts:**
- **Condition**: Determines whether to trigger or terminate retries.
- **BackoffPolicy**: Defines the waiting interval between retries.
- **FailureListener**: Handles (e.g., logging, alerting) upon execution failures.**RetryPolicy** supports logical composition (e.g., `maxAttempts(10) and !runtimeException()`) to express complex retry strategies through a single concept. **BackoffPolicy** allows combinable configurations (e.g., `fixedDelayInSeconds(10) + randomDelayInSeconds(0, 1)`), which represents a 10-second fixed delay with an additional 0–1 second random jitter.
Find more examples [here](demo/src/main).
# License
[Apache License 2.0](LICENSE)