Skip to content

Instantly share code, notes, and snippets.

@schroedermatt
Last active November 16, 2018 15:06
Show Gist options
  • Save schroedermatt/2792124ac000e4752289463ef792edb4 to your computer and use it in GitHub Desktop.
Save schroedermatt/2792124ac000e4752289463ef792edb4 to your computer and use it in GitHub Desktop.
A simple Spring Retry configuration example
@Bean
RetryTemplate retryTemplate() {
RetryTemplate retryTemplate = new RetryTemplate()
FixedBackOffPolicy fixedBackOffPolicy = new FixedBackOffPolicy()
fixedBackOffPolicy.setBackOffPeriod(1000l)
retryTemplate.setBackOffPolicy(fixedBackOffPolicy)
SimpleRetryPolicy retryPolicy = new SimpleRetryPolicy()
retryPolicy.setMaxAttempts(2)
retryTemplate.setRetryPolicy(retryPolicy)
return retryTemplate
}
// example usage (could be replaced with lambda)
retryTemplate.execute(new RetryCallback<Void, RuntimeException>() {
@Override
public Void doWithRetry(RetryContext ctx) {
someService.fetchData();
...
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment