use of org.springframework.retry.backoff.FixedBackOffPolicy in project spring-kafka by spring-projects.
the class DestinationTopicPropertiesFactoryTests method shouldCreateOneRetryPropertyForFixedBackoffWithSingleTopicStrategy.
@Test
void shouldCreateOneRetryPropertyForFixedBackoffWithSingleTopicStrategy() {
// when
FixedBackOffPolicy backOffPolicy = new FixedBackOffPolicy();
backOffPolicy.setBackOffPeriod(1000);
int maxAttempts = 5;
List<Long> backOffValues = new BackOffValuesGenerator(maxAttempts, backOffPolicy).generateValues();
List<DestinationTopic.Properties> propertiesList = new DestinationTopicPropertiesFactory(retryTopicSuffix, dltSuffix, backOffValues, classifier, numPartitions, kafkaOperations, FixedDelayStrategy.SINGLE_TOPIC, dltStrategy, defaultTopicSuffixingStrategy, -1).createProperties();
List<DestinationTopic> destinationTopicList = propertiesList.stream().map(properties -> new DestinationTopic("mainTopic" + properties.suffix(), properties)).collect(Collectors.toList());
// then
assertThat(propertiesList.size() == 3).isTrue();
DestinationTopic.Properties mainTopicProperties = propertiesList.get(0);
DestinationTopic mainDestinationTopic = destinationTopicList.get(0);
assertThat(mainDestinationTopic.isMainTopic()).isTrue();
DestinationTopic.Properties firstRetryProperties = propertiesList.get(1);
assertThat(firstRetryProperties.suffix()).isEqualTo(retryTopicSuffix);
DestinationTopic retryDestinationTopic = destinationTopicList.get(1);
assertThat(retryDestinationTopic.isSingleTopicRetry()).isTrue();
assertThat(retryDestinationTopic.getDestinationDelay()).isEqualTo(1000);
DestinationTopic.Properties dltProperties = propertiesList.get(2);
assertThat(dltProperties.suffix()).isEqualTo(dltSuffix);
assertThat(dltProperties.isDltTopic()).isTrue();
DestinationTopic dltTopic = destinationTopicList.get(2);
assertThat(dltTopic.getDestinationDelay()).isEqualTo(0);
assertThat(dltTopic.getDestinationPartitions()).isEqualTo(numPartitions);
}
use of org.springframework.retry.backoff.FixedBackOffPolicy in project spring-kafka by spring-projects.
the class DestinationTopicPropertiesFactoryTests method shouldCreateRetryPropertiesForFixedBackoffWithMultiTopicStrategy.
@Test
void shouldCreateRetryPropertiesForFixedBackoffWithMultiTopicStrategy() {
// when
FixedBackOffPolicy backOffPolicy = new FixedBackOffPolicy();
backOffPolicy.setBackOffPeriod(5000);
int maxAttempts = 3;
List<Long> backOffValues = new BackOffValuesGenerator(maxAttempts, backOffPolicy).generateValues();
List<DestinationTopic.Properties> propertiesList = new DestinationTopicPropertiesFactory(retryTopicSuffix, dltSuffix, backOffValues, classifier, numPartitions, kafkaOperations, FixedDelayStrategy.MULTIPLE_TOPICS, dltStrategy, defaultTopicSuffixingStrategy, -1).createProperties();
List<DestinationTopic> destinationTopicList = propertiesList.stream().map(properties -> new DestinationTopic("mainTopic" + properties.suffix(), properties)).collect(Collectors.toList());
// then
assertThat(propertiesList.size() == 4).isTrue();
DestinationTopic.Properties mainTopicProperties = propertiesList.get(0);
DestinationTopic mainDestinationTopic = destinationTopicList.get(0);
assertThat(mainDestinationTopic.isMainTopic()).isTrue();
DestinationTopic.Properties firstRetryProperties = propertiesList.get(1);
assertThat(firstRetryProperties.suffix()).isEqualTo(retryTopicSuffix + "-0");
DestinationTopic retryDestinationTopic = destinationTopicList.get(1);
assertThat(retryDestinationTopic.isSingleTopicRetry()).isFalse();
assertThat(retryDestinationTopic.getDestinationDelay()).isEqualTo(5000);
DestinationTopic.Properties secondRetryProperties = propertiesList.get(2);
assertThat(secondRetryProperties.suffix()).isEqualTo(retryTopicSuffix + "-1");
DestinationTopic secondRetryDestinationTopic = destinationTopicList.get(2);
assertThat(secondRetryDestinationTopic.isSingleTopicRetry()).isFalse();
assertThat(secondRetryDestinationTopic.getDestinationDelay()).isEqualTo(5000);
DestinationTopic.Properties dltProperties = propertiesList.get(3);
assertThat(dltProperties.suffix()).isEqualTo(dltSuffix);
assertThat(dltProperties.isDltTopic()).isTrue();
DestinationTopic dltTopic = destinationTopicList.get(3);
assertThat(dltTopic.getDestinationDelay()).isEqualTo(0);
assertThat(dltTopic.getDestinationPartitions()).isEqualTo(numPartitions);
}
use of org.springframework.retry.backoff.FixedBackOffPolicy in project rhsm-subscriptions by RedHatInsights.
the class TallyWorkerConfiguration method cloudigradeRetryTemplate.
@Bean(name = "cloudigradeRetryTemplate")
public RetryTemplate cloudigradeRetryTemplate(ApplicationProperties applicationProperties) {
SimpleRetryPolicy retryPolicy = new SimpleRetryPolicy();
retryPolicy.setMaxAttempts(applicationProperties.getCloudigradeMaxAttempts());
FixedBackOffPolicy backOffPolicy = new FixedBackOffPolicy();
backOffPolicy.setBackOffPeriod(2000L);
RetryTemplate retryTemplate = new RetryTemplate();
retryTemplate.setRetryPolicy(retryPolicy);
retryTemplate.setBackOffPolicy(backOffPolicy);
return retryTemplate;
}
use of org.springframework.retry.backoff.FixedBackOffPolicy in project powop by RBGKew.
the class GetResourceClient method getWithRetry.
public ExitStatus getWithRetry(RetryCallback<ExitStatus, Exception> callback) {
RetryTemplate retryTemplate = new RetryTemplate();
FixedBackOffPolicy backOffPolicy = new FixedBackOffPolicy();
Map<Class<? extends Throwable>, Boolean> retryableExceptions = new HashMap<Class<? extends Throwable>, Boolean>();
retryableExceptions.put(ClientProtocolException.class, Boolean.TRUE);
retryableExceptions.put(IOException.class, Boolean.TRUE);
SimpleRetryPolicy retryPolicy = new SimpleRetryPolicy(retryAttempts, retryableExceptions);
backOffPolicy.setBackOffPeriod(backoffPeriod);
retryTemplate.setListeners(retryListeners);
retryTemplate.setBackOffPolicy(backOffPolicy);
retryTemplate.setRetryPolicy(retryPolicy);
try {
return retryTemplate.execute(callback);
} catch (Exception e) {
logger.error("Retry processing failed " + e.getMessage());
return ExitStatus.FAILED;
}
}
use of org.springframework.retry.backoff.FixedBackOffPolicy in project spring-boot-examples by qct.
the class RetryServiceMain method main.
public static void main(String[] args) throws Throwable {
final AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(RetryServiceMain.class);
final RetryService retryService = applicationContext.getBean(RetryService.class);
RetryTemplate template = new RetryTemplate();
template.setRetryPolicy(new SimpleRetryPolicy());
template.setBackOffPolicy(new FixedBackOffPolicy());
template.registerListener(new StatisticsListener(new DefaultStatisticsRepository()));
Object execute = template.execute(new RetryCallback<Integer, Exception>() {
int i = 5;
@Override
public Integer doWithRetry(RetryContext context) throws Exception {
throw new Exception();
}
});
// String result = retryService.someService();
// System.out.println(result);
}
Aggregations