0

need to use SimpleRetryPolicy and TimeoutRetryPolicy together so i can set max-attempt and timeout both for a retrytemplate

@Bean
@Qualifier(value = "MyRetryBean")
public RetryTemplate grafanaRetryTemplate() {
    RetryTemplate retryTemplate = new RetryTemplate();

    FixedBackOffPolicy fixedBackOffPolicy = new FixedBackOffPolicy();
    fixedBackOffPolicy.setBackOffPeriod(4000);
    retryTemplate.setBackOffPolicy(fixedBackOffPolicy);

    SimpleRetryPolicy retryPolicy = new SimpleRetryPolicy();
    retryPolicy.setMaxAttempts(4);
    retryTemplate.setRetryPolicy(retryPolicy);


    TimeoutRetryPolicy timeOutretryPolicy = new TimeoutRetryPolicy();

    timeOutretryPolicy.setTimeout(100000);

retryTemplate.setRetryPolicy(timeOutretryPolicy);

    return retryTemplate;
}
Satyajeet
  • 15
  • 6

1 Answers1

1

You can have only one policy. Use the CompositeRetryPolicy to combine them.

Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • Thank you so much , can you please help me with how to achieve @recover functionality template? – Satyajeet Sep 08 '19 at 05:03
  • Don't ask follow-up questions in comments. Always ask a new question. Use an execute() method that takes a RecoveryCallback. See the javadocs. If you need more help, ask a new question with more details. – Gary Russell Sep 08 '19 at 08:11