Skip to content

vyag/sakura-retry

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

287 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Maven Central Version Maven Central Last Update Java CI with Maven

中文 | 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.

Example:

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.

License

Apache License 2.0

About

An elegant JVM library for transient failure handling.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages