Last active
November 16, 2018 15:06
-
-
Save schroedermatt/2792124ac000e4752289463ef792edb4 to your computer and use it in GitHub Desktop.
A simple Spring Retry configuration example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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