Java Functional Retry with resilience4j-retry

We will go through specific module(Resilience4j-Retry) from Resilience4j which is a fault tolerance library designed for Java8 and functional programming and it is lightweight library with minimal dependencies (mainly vavr) 

When you retry , there are many cases for example :

  • cross micro services communication for remote systems calls which most likely will need  circuit breaker logic added as well
  • if you have business or functional logic that need to get a consistent end state and most likely it is asynchronous Flow

Ok , what you need to do to start using resileience4j retry :

if you are using maven:

if you are using gradle :

What can be covered by the retry module of resilience4j :

  • Synchronous retry and Asynchronous retry
  • Rety on exceptions or response predicate  which can be useful if you want to retry on specific response value not just thrown exceptions
  • Back-off strategy for the retry configuration plus max retry attempts
  • Ignoring set of exceptions to not retry on
  • It has support for checked(exception handling added) and unchecked functions executions (ex Function , Supplier , Callable , Runnable..)
  • it could be integrated with spring if needed.

Now showing examples of the mentioned features up:

How to configure the Asynchronous retry , full code for testing resilience4j retry on Github

For Synchronous calls , you have many options (Supplier , Callable , Function , plus Checked version of them, please check resilience4j retry APIs for more information) :

Example :

For more information , please check resilience4j Github and the code samples on GitHub as well .

In the next blogs I will cover spring and spring boot integration .

References :



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s