For example:
Simple Retry Example
Simple Retry Example
@Retryable
List<Book> listBooks() {
// ...
Simple Retry Example
@Retryable
open fun listBooks(): List<Book> {
// ...
The multiplier
value of the @Retryable
annotation can be used to configure a multiplier used to calculate the delay between retries, thus allowing exponential retry support.
Note also that the annotation can be applied on interfaces and the behaviour will be inherited through annotation metadata. The implication of this is that @Retryable
can be used in combination with such as the HTTP Client annotation.
To customize retry behaviour you can set the attempts
and delay
members, For example to configure 5 attempts with a 2 second delay:
Setting Retry Attempts
delay = "2s" )
Book findBook(String title) {
// ...
Setting Retry Attempts
@Retryable(attempts = "5", delay = "2s")
open fun findBook(title: String): Book {
// ...
Notice how both and delay
are defined as strings. This is to support configurability through annotation metadata. For example you can allow the retry policy to be configured using property placeholder resolution:
Setting Retry via Configuration
Setting Retry via Configuration
delay = "\${book.retry.delay:1s}")
Book getBook(String title) {
// ...
@Retryable(attempts = "\${book.retry.attempts:3}", delay = "\${book.retry.delay:1s}")
open fun getBook(title: String): Book {
// ...
With the above in place if book.retry.attempts
is specified in configuration it wil be bound the value of the attempts
member of the annotation via annotation metadata.