Java Code Examples for org.springframework.retry.support.RetryTemplate#setBackOffPolicy()

The following examples show how to use org.springframework.retry.support.RetryTemplate#setBackOffPolicy() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Application.java    From mojito with Apache License 2.0 6 votes vote down vote up
@Bean
public RetryTemplate retryTemplate() {
    SimpleRetryPolicy retryPolicy = new SimpleRetryPolicy();
    retryPolicy.setMaxAttempts(5);

    ExponentialRandomBackOffPolicy exponentialRandomBackOffPolicy = new ExponentialRandomBackOffPolicy();
    exponentialRandomBackOffPolicy.setInitialInterval(10);
    exponentialRandomBackOffPolicy.setMultiplier(3);
    exponentialRandomBackOffPolicy.setMaxInterval(5000);

    RetryTemplate template = new RetryTemplate();
    template.setRetryPolicy(retryPolicy);
    template.setBackOffPolicy(exponentialRandomBackOffPolicy);
    template.setThrowLastExceptionOnExhausted(true);

    return template;
}
 
Example 2
Source File: KafkaTopicProvisioner.java    From spring-cloud-stream-binder-kafka with Apache License 2.0 6 votes vote down vote up
@Override
public void afterPropertiesSet() {
	if (this.metadataRetryOperations == null) {
		RetryTemplate retryTemplate = new RetryTemplate();

		SimpleRetryPolicy simpleRetryPolicy = new SimpleRetryPolicy();
		simpleRetryPolicy.setMaxAttempts(10);
		retryTemplate.setRetryPolicy(simpleRetryPolicy);

		ExponentialBackOffPolicy backOffPolicy = new ExponentialBackOffPolicy();
		backOffPolicy.setInitialInterval(100);
		backOffPolicy.setMultiplier(2);
		backOffPolicy.setMaxInterval(1000);
		retryTemplate.setBackOffPolicy(backOffPolicy);
		this.metadataRetryOperations = retryTemplate;
	}
}
 
Example 3
Source File: JerseyClientRetryTemplateConfig.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Bean
public RetryTemplate jerseyClientRetryTemplate() {
    RetryTemplate retryTemplate = new RetryTemplate();
    ExponentialBackOffPolicy exponentialBackOffPolicy = new ExponentialBackOffPolicy();
    exponentialBackOffPolicy.setInitialInterval(INITIAL_BACKOFF_IN_MILLIS);
    exponentialBackOffPolicy.setMultiplier(2.0);
    exponentialBackOffPolicy.setMaxInterval(MAX_BACKOFF_IN_MILLIS);
    retryTemplate.setBackOffPolicy(exponentialBackOffPolicy);
    retryTemplate.setRetryPolicy(new JerseyClientRetryPolicy());
    return retryTemplate;
}
 
Example 4
Source File: AmqpContextConfig.java    From sinavi-jfw with Apache License 2.0 5 votes vote down vote up
/**
 * {@link RetryTemplate}のインスタンスをDIコンテナに登録します。
 * @return {@link RetryTemplate}のインスタンス
 */
protected RetryTemplate retryTemplate() {
    RetryTemplate template = new RetryTemplate();
    template.setBackOffPolicy(backOffPolicy());
    template.setRetryPolicy(simpleRetryPolicy());
    return template;
}
 
Example 5
Source File: OTXConnection.java    From OTX-Java-SDK with Apache License 2.0 5 votes vote down vote up
/**
 * Internal API to configure RestTemplate
 *
 * @param apiKey - API key to configure authorization header
 */
private void configureRestTemplate(String apiKey) {
    ClientHttpRequestFactory requestFactory = HTTPConfig.createRequestFactory(apiKey);
    restTemplate = new RestTemplate(requestFactory);
    retryTemplate = new RetryTemplate();
    retryTemplate.setBackOffPolicy(new ExponentialBackOffPolicy());
}
 
Example 6
Source File: JpaDeploymentManagement.java    From hawkbit with Eclipse Public License 1.0 5 votes vote down vote up
private static RetryTemplate createRetryTemplate() {
    final RetryTemplate template = new RetryTemplate();

    final FixedBackOffPolicy backOffPolicy = new FixedBackOffPolicy();
    backOffPolicy.setBackOffPeriod(Constants.TX_RT_DELAY);
    template.setBackOffPolicy(backOffPolicy);

    final SimpleRetryPolicy retryPolicy = new SimpleRetryPolicy(Constants.TX_RT_MAX,
            Collections.singletonMap(ConcurrencyFailureException.class, true));
    template.setRetryPolicy(retryPolicy);

    return template;
}
 
Example 7
Source File: InitializrStatsAutoConfigurationTests.java    From initializr with Apache License 2.0 5 votes vote down vote up
@Bean
RetryTemplate statsRetryTemplate() {
	RetryTemplate retryTemplate = new RetryTemplate();
	ExponentialBackOffPolicy backOffPolicy = new ExponentialBackOffPolicy();
	backOffPolicy.setMultiplier(10);
	retryTemplate.setBackOffPolicy(backOffPolicy);
	return retryTemplate;
}
 
Example 8
Source File: AggregateCounterSinkStoreConfiguration.java    From spring-cloud-stream-app-starters with Apache License 2.0 5 votes vote down vote up
@Bean
public RetryOperations retryOperations() {
	RetryTemplate retryTemplate = new RetryTemplate();
	retryTemplate.setRetryPolicy(new SimpleRetryPolicy(3,
			Collections.<Class<? extends Throwable>, Boolean>singletonMap(RedisConnectionFailureException.class, true)));
	ExponentialBackOffPolicy backOffPolicy = new ExponentialBackOffPolicy();
	backOffPolicy.setInitialInterval(1000L);
	backOffPolicy.setMaxInterval(1000L);
	backOffPolicy.setMultiplier(2);
	retryTemplate.setBackOffPolicy(backOffPolicy);
	return retryTemplate;
}
 
Example 9
Source File: FieldValueCounterSinkStoreConfiguration.java    From spring-cloud-stream-app-starters with Apache License 2.0 5 votes vote down vote up
@Bean
public RetryOperations retryOperations() {
	RetryTemplate retryTemplate = new RetryTemplate();
	retryTemplate.setRetryPolicy(new SimpleRetryPolicy(3, Collections.<Class<? extends Throwable>, Boolean>singletonMap(RedisConnectionFailureException.class, true)));
	ExponentialBackOffPolicy backOffPolicy = new ExponentialBackOffPolicy();
	backOffPolicy.setInitialInterval(1000L);
	backOffPolicy.setMaxInterval(1000L);
	backOffPolicy.setMultiplier(2);
	retryTemplate.setBackOffPolicy(backOffPolicy);
	return retryTemplate;
}
 
Example 10
Source File: RabbitMQConfig.java    From micro-service with MIT License 5 votes vote down vote up
@Bean()
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public RabbitTemplate rabbitTemplate() {
	
	ExponentialBackOffPolicy backOffPolicy = new ExponentialBackOffPolicy();
	backOffPolicy.setInitialInterval(500);
	backOffPolicy.setMultiplier(10.0);
	backOffPolicy.setMaxInterval(10000);
	
	RetryTemplate retryTemplate = new RetryTemplate();
	retryTemplate.setBackOffPolicy(backOffPolicy);
	
	RabbitTemplate template = new RabbitTemplate(connectionFactory());
	template.setRetryTemplate(retryTemplate);
	template.setChannelTransacted(false);
	
	template.setConfirmCallback(new ConfirmCallback() {
		@Override
		public void confirm(CorrelationData correlationData, boolean ack, String cause) {
			if(ack) {
				logger.info("发送消息成功, correlationId={}", correlationData.getId());
			} else {
				logger.info("发送消息失败, correlationId={}, cause={}", correlationData.getId(), cause);
			}
		}
	});
	
	return template;
}
 
Example 11
Source File: CmApiRetryTemplateConfig.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Bean
public RetryTemplate cmApiRetryTemplate() {
    RetryTemplate retryTemplate = new RetryTemplate();
    FixedBackOffPolicy fixedBackOffPolicy = new FixedBackOffPolicy();
    fixedBackOffPolicy.setBackOffPeriod(BACK_OFF_PERIOD);
    retryTemplate.setBackOffPolicy(fixedBackOffPolicy);
    retryTemplate.setRetryPolicy(new ApiExceptionRetryPolicy());
    return retryTemplate;
}
 
Example 12
Source File: RetryServiceImpl.java    From IridiumApplicationTesting with MIT License 5 votes vote down vote up
@Override
public RetryTemplate getRetryTemplate() {
	final SimpleRetryPolicy policy = new SimpleRetryPolicy();
	policy.setMaxAttempts(Constants.WEBDRIVER_ACTION_RETRIES);

	final ExponentialBackOffPolicy backoff = new ExponentialBackOffPolicy();
	backoff.setInitialInterval(RETRY_INTERVAL);

	final RetryTemplate template = new RetryTemplate();
	template.setRetryPolicy(policy);
	template.setBackOffPolicy(backoff);
	return template;
}
 
Example 13
Source File: CleanupBean.java    From CogStack-Pipeline with Apache License 2.0 5 votes vote down vote up
public RetryTemplate getRetryTemplate(){
//        TimeoutRetryPolicy retryPolicy = new TimeoutRetryPolicy();
//        retryPolicy.setTimeout(Long.valueOf(env.getProperty("shutdownTimeout")));
        AlwaysRetryPolicy retryPolicy = new AlwaysRetryPolicy();
        FixedBackOffPolicy backOffPolicy = new FixedBackOffPolicy();
        backOffPolicy.setBackOffPeriod(5000);

        RetryTemplate template = new RetryTemplate();
        template.setRetryPolicy(retryPolicy);
        template.setBackOffPolicy(backOffPolicy);
        return template;
    }
 
Example 14
Source File: WebserviceDocumentItemProcessor.java    From CogStack-Pipeline with Apache License 2.0 5 votes vote down vote up
private RetryTemplate getRetryTemplate(){
    TimeoutRetryPolicy retryPolicy = new TimeoutRetryPolicy();
    retryPolicy.setTimeout(retryTimeoutMs);
    FixedBackOffPolicy backOffPolicy = new FixedBackOffPolicy();
    backOffPolicy.setBackOffPeriod(retryBackoffMs);

    RetryTemplate template = new RetryTemplate();
    template.setRetryPolicy(retryPolicy);
    template.setBackOffPolicy(backOffPolicy);
    return template;
}
 
Example 15
Source File: RetryConfig.java    From batchers with Apache License 2.0 5 votes vote down vote up
public RetryTemplate createRetryTemplate() {
    Map<Class<? extends Throwable>, Boolean> exceptions = new HashMap<>();
    exceptions.put(TaxWebServiceNonFatalException.class, true);

    RetryTemplate template = new RetryTemplate();
    SimpleRetryPolicy retryPolicy = new SimpleRetryPolicy(maxAttempts, exceptions);
    template.setRetryPolicy(retryPolicy);

    ExponentialBackOffPolicy backOffPolicy = new ExponentialBackOffPolicy();
    backOffPolicy.setInitialInterval(initialInterval);
    template.setBackOffPolicy(backOffPolicy);

    return template;
}
 
Example 16
Source File: ExceptionQueueContextConfig.java    From sinavi-jfw with Apache License 2.0 5 votes vote down vote up
/**
 * リトライのポリシー(間隔、回数)を設定し、
 * {@link RetryOperations}のインスタンスをDIコンテナに登録します。
 * @return {@link RetryTemplate}のインスタンス
 */
@Bean
public RetryOperations retryOperations() {
    RetryTemplate template = new RetryTemplate();
    template.setRetryPolicy(retryPolicy());
    template.setBackOffPolicy(backOffPolicy());
    return template;
}
 
Example 17
Source File: RetryExampleApplication.java    From blog-examples with Apache License 2.0 5 votes vote down vote up
@Bean
public RetryTemplate retryTemplate() {
    SimpleRetryPolicy retryPolicy = new SimpleRetryPolicy();
    retryPolicy.setMaxAttempts(5);

    FixedBackOffPolicy backOffPolicy = new FixedBackOffPolicy();
    backOffPolicy.setBackOffPeriod(1500); // 1.5 seconds

    RetryTemplate template = new RetryTemplate();
    template.setRetryPolicy(retryPolicy);
    template.setBackOffPolicy(backOffPolicy);

    return template;
}
 
Example 18
Source File: RabbitAutoConfiguration.java    From summerframework with Apache License 2.0 5 votes vote down vote up
private RetryTemplate createRetryTemplate(RabbitProperties.Retry properties) {
    RetryTemplate template = new RetryTemplate();
    SimpleRetryPolicy policy = new SimpleRetryPolicy();
    policy.setMaxAttempts(properties.getMaxAttempts());
    template.setRetryPolicy(policy);
    ExponentialBackOffPolicy backOffPolicy = new ExponentialBackOffPolicy();
    backOffPolicy.setInitialInterval(properties.getInitialInterval());
    backOffPolicy.setMultiplier(properties.getMultiplier());
    backOffPolicy.setMaxInterval(properties.getMaxInterval());
    template.setBackOffPolicy(backOffPolicy);
    return template;
}
 
Example 19
Source File: ClickingStepDefinitions.java    From IridiumApplicationTesting with MIT License 4 votes vote down vote up
/**
 * Clicks a link that may or may not be visible on the page
 *
 * @param alias       If this word is found in the step, it means the linkContent is found from the data
 *                    set.
 * @param linkContent The text content of the link we are clicking
 * @param timesAlias  If this word is found in the step, it means the times is found from the
 *                    data set.
 * @param times       If this text is set, the click operation will be repeated the specified number of times.
 * @param exists      If this text is set, an error that would be thrown because the element was not found
 *                    is ignored. Essentially setting this text makes this an optional statement.
 */
@When("^I click (?:a|an|the) hidden link with the text content( alias)? of \"([^\"]*)\"(?:( alias)? \"(.*?)\" times)?( if it exists)?$")
public void clickHiddenLinkStep(
	final String alias,
	final String linkContent,
	final String timesAlias,
	final String times,
	final String exists) {

	try {
		final Integer fixedTimes = countConverter.convertCountToInteger(timesAlias, times);

		final String text = autoAliasUtils.getValue(
			linkContent, StringUtils.isNotBlank(alias), State.getFeatureStateForThread());

		checkState(text != null, "the aliased link content does not exist");

		final WebDriver webDriver = State.getThreadDesiredCapabilityMap().getWebDriverForThread();

		for (int i = 0; i < fixedTimes; ++i) {
			final RetryTemplate template = new RetryTemplate();
			final SimpleRetryPolicy policy = new SimpleRetryPolicy();
			policy.setMaxAttempts(Constants.WEBDRIVER_ACTION_RETRIES);
			template.setRetryPolicy(policy);
			final FixedBackOffPolicy fixedBackOffPolicy = new FixedBackOffPolicy();
			template.setBackOffPolicy(fixedBackOffPolicy);
			template.execute(context -> {
				final WebElement element = browserInteropUtils.getLinkByText(webDriver, text);

				mouseMovementUtils.mouseGlide(
					webDriver,
					(JavascriptExecutor) webDriver,
					element,
					Constants.MOUSE_MOVE_TIME,
					Constants.MOUSE_MOVE_STEPS);

				final JavascriptExecutor js = (JavascriptExecutor) webDriver;
				js.executeScript("arguments[0].click();", element);
				return null;
			});

			sleepUtils.sleep(State.getFeatureStateForThread().getDefaultSleep());
		}
	} catch (final TimeoutException | NoSuchElementException ex) {
		if (StringUtils.isBlank(exists)) {
			throw ex;
		}
	}
}
 
Example 20
Source File: ClickingStepDefinitions.java    From IridiumApplicationTesting with MIT License 4 votes vote down vote up
/**
 * Clicks a link on the page
 *
 * @param alias       If this word is found in the step, it means the linkContent is found from the data
 *                    set.
 * @param linkContent The text content of the link we are clicking
 * @param timesAlias  If this word is found in the step, it means the times is found from the
 *                    data set.
 * @param times       If this text is set, the click operation will be repeated the specified number of times.
 * @param exists      If this text is set, an error that would be thrown because the element was not found
 *                    is ignored. Essentially setting this text makes this an optional statement.
 */
@When("^I click (?:a|an|the) link with the text content of( alias)? \"([^\"]*)\"(?:( alias)? \"(.*?)\" times)?( if it exists)?$")
public void clickLinkStep(
	final String alias,
	final String linkContent,
	final String timesAlias,
	final String times,
	final String exists) {

	try {
		final Integer fixedTimes = countConverter.convertCountToInteger(timesAlias, times);

		final String text = autoAliasUtils.getValue(
			linkContent, StringUtils.isNotBlank(alias), State.getFeatureStateForThread());

		checkState(text != null, "the aliased link content does not exist");

		final WebDriver webDriver = State.getThreadDesiredCapabilityMap().getWebDriverForThread();

		for (int i = 0; i < fixedTimes; ++i) {
			final WebElement element = browserInteropUtils.getLinkByText(webDriver, text);

			mouseMovementUtils.mouseGlide(
				webDriver,
				(JavascriptExecutor) webDriver,
				element,
				Constants.MOUSE_MOVE_TIME,
				Constants.MOUSE_MOVE_STEPS);

			final RetryTemplate template = new RetryTemplate();
			final SimpleRetryPolicy policy = new SimpleRetryPolicy();
			policy.setMaxAttempts(Constants.WEBDRIVER_ACTION_RETRIES);
			template.setRetryPolicy(policy);
			final FixedBackOffPolicy fixedBackOffPolicy = new FixedBackOffPolicy();
			template.setBackOffPolicy(fixedBackOffPolicy);
			template.execute(context -> {
				element.click();
				return null;
			});

			sleepUtils.sleep(State.getFeatureStateForThread().getDefaultSleep());
		}
	} catch (final TimeoutException | NoSuchElementException ex) {
		if (StringUtils.isBlank(exists)) {
			throw ex;
		}
	}
}