Spring Retry traversingCauses example (using RetryTemplateBuilder)

In my previous post under Spring Retry, I showed with example how to retry failed operations only for specific exceptions. So for example if we configure Spring Retry (as shown in the below code) to retry only when NullPointerException is thrown Code snippet 1 RetryTemplateBuilder retryTemplateBuilder = RetryTemplate.builder(); retryTemplateBuilder.retryOn(NullPointerException.class) Spring Retry will retry the failed…… Continue reading Spring Retry traversingCauses example (using RetryTemplateBuilder)

Configuring Custom BackOff Policy for RetryTemplate (using RetryTemplateBuilder)

Hi everybody, in this post under Spring Retry I will show you with example how to configure custom BackOff policy using RetryTemplateBuilder. For the example we will use the below service class Service1 class public class Service1 { private int i = 0; private int j = 0; public void executeWithException() { i = i…… Continue reading Configuring Custom BackOff Policy for RetryTemplate (using RetryTemplateBuilder)

Configuring Custom Retry Policy for RetryTemplate (using RetryTemplateBuilder)

In this post under Spring Retry, I will show with example how to configure your own custom Retry Policy using RetryTemplateBuilder class. For this example, we will use modified version of Spring’s MaxAttemptsRetryPolicy, as shown below CustomMaxAttemptsRetryPolicy import org.springframework.retry.RetryContext; import org.springframework.retry.policy.MaxAttemptsRetryPolicy; public class CustomMaxAttemptsRetryPolicy extends MaxAttemptsRetryPolicy { private String name; public CustomMaxAttemptsRetryPolicy(String name) { this.name…… Continue reading Configuring Custom Retry Policy for RetryTemplate (using RetryTemplateBuilder)

Configuring ExponentialBackOffPolicy for RetryTemplate (using RetryTemplateBuilder)

In this post under Spring Retry, I will show with example how to configure ExponentialBackOffPolicy using RetryTemplateBuilder. First lets recap what is ExponentialBackOffPolicy is. ExponentialBackOffPolicy increases the backoff period at every retry attempt by a specified number. ExponentialBackOffPolicy requires three inputs for it to work, which are1) initialInterval –> the backoff period used at first…… Continue reading Configuring ExponentialBackOffPolicy for RetryTemplate (using RetryTemplateBuilder)

Configuring UniformRandomBackOffPolicy for RetryTemplate (using RetryTemplateBuilder)

In this post under Spring Retry, I will show with example how to configure UniformRandomBackOffPolicy using RetryTemplateBuilder. But before that lets recap what is UniformRandomBackOffPolicy. UniformRandomBackOffPolicy chooses a random time in ms between user configured MinBackOffPeriod and MaxBackOffPeriod and then before a failed operations is retried, it pauses for that time. For our example we…… Continue reading Configuring UniformRandomBackOffPolicy for RetryTemplate (using RetryTemplateBuilder)

Configuring FixedBackOffPolicy for RetryTemplate (using RetryTemplateBuilder)

In this post under Spring Retry, I will show with example how to configure FixedBackOffPolicy using RetryTemplateBuilder. Before we start lets just recap what is BackOffPolicy and FixedBackOffPolicy. Backoff policies help us define different policies which will tell Spring Retry how long to wait before retrying a failed operation. FixedBackOffPolicy is one of the implmentations…… Continue reading Configuring FixedBackOffPolicy for RetryTemplate (using RetryTemplateBuilder)

Configuring TimeoutRetryPolicy for RetryTemplate (using RetryTemplateBuilder)

In this post under Spring Retry, I will show with example how to configure TimeoutRetryPolicy using RetryTemplateBuilder. Lets refresh what is TimeoutRetryPolicy. TimeoutRetryPolicy tells Spring retry to retry a failed operation as many times as possible before the timeout happens. Once timeout happens the Spring retry stopsretrying the failed operation. Now lets see how to…… Continue reading Configuring TimeoutRetryPolicy for RetryTemplate (using RetryTemplateBuilder)

Configuring MaxAttemptsRetryPolicy for RetryTemplate (using RetryTemplateBuilder)

In this post under Spring Retry, I will show with example how to configure MaxAttemptsRetryPolicy using RetryTemplateBuilder. Lets refresh what is MaxAttemptsRetryPolicy. MaxAttemptsRetryPolicy tells Spring retry to retry a failed operation for a fixed number of times. Now lets see how to configure using RetryTemplateBuilder. Below is the xml code for your reference XML Code…… Continue reading Configuring MaxAttemptsRetryPolicy for RetryTemplate (using RetryTemplateBuilder)

Configuring RetryListener for RetryTemplate (using RetryTemplateBuilder)

In this post under Spring Retry, I will show with example how to configure RetryListener using RetryTemplateBuilder class. First we will create a custom listener class which implements RetryListener interface as shown below CustomRetryListener1 import org.springframework.retry.RetryCallback; import org.springframework.retry.RetryContext; import org.springframework.retry.RetryListener; public class CustomRetryListener1 implements RetryListener { @Override public <T, E extends Throwable> void close(RetryContext arg0,…… Continue reading Configuring RetryListener for RetryTemplate (using RetryTemplateBuilder)

Spring Retry simple example (using builder pattern)

In this post under Spring Retry, I will explain how to configure Spring Retry framework into your application using builder pattern with simple example At minimum, you need the below jars in your classpath1) spring-retry-1.3.1.jar2) commons-logging-1.2.jar3) spring-core-4.3.22.RELEASE.jar4) spring-aop-4.3.22.REELEASE.jar5) spring-beans-4.3.22.RELEASE.jar6) spring-context-4.3.22.RELEASE.jar7) spring-expression-4.3.22.RELEASE.jar8) aspectjweaver-1.8.9.jar For the example I will the below service class Service1 class public class…… Continue reading Spring Retry simple example (using builder pattern)