当前位置: 首页>>代码示例>>Java>>正文


Java RetryTemplate类代码示例

本文整理汇总了Java中org.springframework.retry.support.RetryTemplate的典型用法代码示例。如果您正苦于以下问题:Java RetryTemplate类的具体用法?Java RetryTemplate怎么用?Java RetryTemplate使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


RetryTemplate类属于org.springframework.retry.support包,在下文中一共展示了RetryTemplate类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: assertProcessEnded

import org.springframework.retry.support.RetryTemplate; //导入依赖的package包/类
private void assertProcessEnded(final ProcessInstance pi) {
    // fetch active executions
    RetryTemplate retryTemplate = new RetryTemplate();
    final SimpleRetryPolicy retryPolicy = new SimpleRetryPolicy();
    retryPolicy.setMaxAttempts(5);
    retryTemplate.setRetryPolicy(retryPolicy);
    FixedBackOffPolicy backOffPolicy = new FixedBackOffPolicy();
    retryTemplate.setBackOffPolicy(backOffPolicy);
    retryTemplate.execute(new RetryCallback<Void, RuntimeException>() {
        @Override
        public Void doWithRetry(RetryContext retryContext) throws RuntimeException {
            List<ProcessInstance> processInstances = runtimeService.createProcessInstanceQuery().list();
            int processCount = processInstances.size();
            LOGGER.info("waiting for process to end (Still {} process running).", processCount);
            if (processCount > 0) {
                for (ProcessInstance processInstance : processInstances) {
                    LOGGER.info("Process info: {} ", dumpprocessInstance(processInstance));
                }
                throw new IllegalStateException("Some process still running. Left :" + processCount);
            }
            return null;
        }
    });
}
 
开发者ID:orange-cloudfoundry,项目名称:elpaaso-core,代码行数:25,代码来源:ErrorCatchingTest.java

示例2: actOnItem

import org.springframework.retry.support.RetryTemplate; //导入依赖的package包/类
/**
 * The main point of entry into this class.
 *
 * Call this with an item and {@link #asynchronousAction(Object)} will be called with the same item to do the action
 * asynchronously.
 *
 * @param objectToActOn The item to do an action on.
 * @return A {@link CompletableFuture} that will complete once the action completes without failure.
 */
protected CompletableFuture<S> actOnItem(final T objectToActOn) {
	return CompletableFuture.supplyAsync(() -> {
		RetryTemplate retry = retryTemplate();

		API_LOG.info("Trying to execute action");
		return retry.execute(context -> {
			if (context.getLastThrowable() != null) {
				API_LOG.warn("Last try resulted in a thrown throwable", context.getLastThrowable());
			}
			if (context.getRetryCount() > 0) {
				API_LOG.warn("Retry {} - trying to execute action again", context.getRetryCount());
			}
			return this.asynchronousAction(objectToActOn);
		});
	}, taskExecutor);
}
 
开发者ID:CMSgov,项目名称:qpp-conversion-tool,代码行数:26,代码来源:AnyOrderActionService.java

示例3: retryKafkaListenerContainerFactory

import org.springframework.retry.support.RetryTemplate; //导入依赖的package包/类
@Bean
public ConcurrentKafkaListenerContainerFactory<String, String> retryKafkaListenerContainerFactory() {
	ConcurrentKafkaListenerContainerFactory<String, String> factory =
			new ConcurrentKafkaListenerContainerFactory<>();
	factory.setConsumerFactory(consumerFactory());
	factory.setRetryTemplate(new RetryTemplate());
	factory.setRecordFilterStrategy(new RecordFilterStrategy<String, String>() {

		@Override
		public boolean filter(ConsumerRecord<String, String> consumerRecord) {
			return consumerRecord.value().equals("bar");
		}

	});
	return factory;
}
 
开发者ID:SpringOnePlatform2016,项目名称:grussell-spring-kafka,代码行数:17,代码来源:CommonConfiguration.java

示例4: retryTemplate

import org.springframework.retry.support.RetryTemplate; //导入依赖的package包/类
/**
 * Returns a retry template that always retries.  Starts with a second interval between retries and doubles that interval up
 * to a minute for each retry.
 *
 * @return A retry template.
 */
protected RetryTemplate retryTemplate() {
	RetryTemplate retry = new RetryTemplate();

	Map<Class<? extends Throwable>, Boolean> stopExceptions =
			Collections.singletonMap(InterruptedException.class, Boolean.FALSE);
	SimpleRetryPolicy retryPolicy =
			new SimpleRetryPolicy(Integer.MAX_VALUE, stopExceptions, true, true);

	retry.setRetryPolicy(retryPolicy);

	ExponentialBackOffPolicy backOffPolicy = new ExponentialBackOffPolicy();
	backOffPolicy.setInitialInterval(1000);
	backOffPolicy.setMultiplier(2.0);
	backOffPolicy.setMaxInterval(60000);
	retry.setBackOffPolicy(backOffPolicy);

	return retry;
}
 
开发者ID:CMSgov,项目名称:qpp-conversion-tool,代码行数:25,代码来源:AnyOrderActionService.java

示例5: arkClientRetryTemplate

import org.springframework.retry.support.RetryTemplate; //导入依赖的package包/类
@Bean
public RetryTemplate arkClientRetryTemplate() {
    RetryTemplate retryTemplate = new RetryTemplate();

    Map<Class<? extends Throwable>, Boolean> includeExceptions = new HashMap<>();
    includeExceptions.put(RuntimeException.class, true);

    ExponentialBackOffPolicy exponentialBackOffPolicy = new ExponentialBackOffPolicy();
    exponentialBackOffPolicy.setInitialInterval(10);
    exponentialBackOffPolicy.setMultiplier(2.0);
    retryTemplate.setBackOffPolicy(exponentialBackOffPolicy);

    SimpleRetryPolicy retryPolicy = new SimpleRetryPolicy(10, includeExceptions);
    retryPolicy.setMaxAttempts(10);
    retryTemplate.setRetryPolicy(retryPolicy);

    return retryTemplate;
}
 
开发者ID:ark-aces,项目名称:aces-backend,代码行数:19,代码来源:EthBridgeConfig.java

示例6: arkClientRetryTemplate

import org.springframework.retry.support.RetryTemplate; //导入依赖的package包/类
@Bean
public RetryTemplate arkClientRetryTemplate() {
    RetryTemplate retryTemplate = new RetryTemplate();

    Map<Class<? extends Throwable>, Boolean> includeExceptions = new HashMap<>();
    includeExceptions.put(RuntimeException.class, true);

    ExponentialBackOffPolicy exponentialBackOffPolicy = new ExponentialBackOffPolicy();
    exponentialBackOffPolicy.setInitialInterval(100);
    exponentialBackOffPolicy.setMultiplier(2.0);
    retryTemplate.setBackOffPolicy(exponentialBackOffPolicy);

    SimpleRetryPolicy retryPolicy = new SimpleRetryPolicy(5, includeExceptions);
    retryPolicy.setMaxAttempts(5);
    retryTemplate.setRetryPolicy(retryPolicy);

    return retryTemplate;
}
 
开发者ID:bradyo,项目名称:ark-java-smart-bridge-listener,代码行数:19,代码来源:EthBridgeConfig.java

示例7: tempoApiRetryPolicy

import org.springframework.retry.support.RetryTemplate; //导入依赖的package包/类
@Bean
@Qualifier("tempo")
public RetryOperations tempoApiRetryPolicy() {
    final RetryPolicy retryPolicy = createRetryPolicy();

    final ExponentialBackOffPolicy backOffPolicy = new ExponentialBackOffPolicy();
    backOffPolicy.setInitialInterval(2000);
    backOffPolicy.setMultiplier(3);

    final RetryTemplate retryTemplate = new RetryTemplate();
    retryTemplate.setRetryPolicy(retryPolicy);
    retryTemplate.setBackOffPolicy(backOffPolicy);
    retryTemplate.setThrowLastExceptionOnExhausted(true);

    return retryTemplate;
}
 
开发者ID:suomenriistakeskus,项目名称:oma-riista-web,代码行数:17,代码来源:TempoApiConfiguration.java

示例8: verifyConsumer

import org.springframework.retry.support.RetryTemplate; //导入依赖的package包/类
private void verifyConsumer(AbstractEndpoint endpoint) {
	assertThat(endpoint.getClass().getName(), containsString("CompositeRedisQueueMessageDrivenEndpoint"));
	assertEquals(2, TestUtils.getPropertyValue(endpoint, "consumers", Collection.class).size());
	DirectChannel channel = TestUtils.getPropertyValue(
			TestUtils.getPropertyValue(endpoint, "consumers", List.class).get(0),
			"outputChannel", DirectChannel.class);
	assertThat(
			channel.getClass().getName(), containsString(getClassUnderTestName() + "$")); // retry wrapper
	assertThat(
			TestUtils.getPropertyValue(TestUtils.getPropertyValue(endpoint, "consumers", List.class).get(1),
					"outputChannel").getClass().getName(), containsString(getClassUnderTestName() + "$")); // retry wrapper
	RetryTemplate retry = TestUtils.getPropertyValue(channel, "val$retryTemplate", RetryTemplate.class);
	assertEquals(23, TestUtils.getPropertyValue(retry, "retryPolicy.maxAttempts"));
	assertEquals(2000L, TestUtils.getPropertyValue(retry, "backOffPolicy.initialInterval"));
	assertEquals(20000L, TestUtils.getPropertyValue(retry, "backOffPolicy.maxInterval"));
	assertEquals(5.0, TestUtils.getPropertyValue(retry, "backOffPolicy.multiplier"));
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream-binder-redis,代码行数:18,代码来源:RedisBinderTests.java

示例9: afterPropertiesSet

import org.springframework.retry.support.RetryTemplate; //导入依赖的package包/类
@Override
public void afterPropertiesSet() throws Exception {
	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;
	}
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream-binder-kafka,代码行数:18,代码来源:KafkaTopicProvisioner.java

示例10: verifyContainer

import org.springframework.retry.support.RetryTemplate; //导入依赖的package包/类
private SimpleMessageListenerContainer verifyContainer(Lifecycle endpoint) {
	SimpleMessageListenerContainer container;
	RetryTemplate retry;
	container = TestUtils.getPropertyValue(endpoint, "messageListenerContainer",
			SimpleMessageListenerContainer.class);
	assertThat(container.getAcknowledgeMode()).isEqualTo(AcknowledgeMode.NONE);
	assertThat(container.getQueueNames()[0]).startsWith("foo.props.0");
	assertThat(TestUtils.getPropertyValue(container, "transactional", Boolean.class)).isFalse();
	assertThat(TestUtils.getPropertyValue(container, "concurrentConsumers")).isEqualTo(2);
	assertThat(TestUtils.getPropertyValue(container, "maxConcurrentConsumers")).isEqualTo(3);
	assertThat(TestUtils.getPropertyValue(container, "defaultRequeueRejected", Boolean.class)).isFalse();
	assertThat(TestUtils.getPropertyValue(container, "prefetchCount")).isEqualTo(20);
	assertThat(TestUtils.getPropertyValue(container, "txSize")).isEqualTo(10);
	retry = TestUtils.getPropertyValue(endpoint, "retryTemplate", RetryTemplate.class);
	assertThat(TestUtils.getPropertyValue(retry, "retryPolicy.maxAttempts")).isEqualTo(23);
	assertThat(TestUtils.getPropertyValue(retry, "backOffPolicy.initialInterval")).isEqualTo(2000L);
	assertThat(TestUtils.getPropertyValue(retry, "backOffPolicy.maxInterval")).isEqualTo(20000L);
	assertThat(TestUtils.getPropertyValue(retry, "backOffPolicy.multiplier")).isEqualTo(5.0);

	List<?> requestMatchers = TestUtils.getPropertyValue(endpoint, "headerMapper.requestHeaderMatcher.matchers",
			List.class);
	assertThat(requestMatchers).hasSize(1);
	assertThat(TestUtils.getPropertyValue(requestMatchers.get(0), "pattern")).isEqualTo("foo");

	return container;
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream-binder-rabbit,代码行数:27,代码来源:RabbitBinderTests.java

示例11: getRetryTemplate

import org.springframework.retry.support.RetryTemplate; //导入依赖的package包/类
/**
 * Configure and return the retry template.
 */
public RetryTemplate getRetryTemplate(){
    //Create RetryTemplate
    final RetryTemplate retryTemplate = new RetryTemplate();
    
    //Create Fixed back policy
    final FixedBackOffPolicy fixedBackOffPolicy = new FixedBackOffPolicy();
    
    //Set backOffPeriod
    fixedBackOffPolicy.setBackOffPeriod(Long.valueOf(backOffPeriod));
    
    //Set the backoff policy
    retryTemplate.setBackOffPolicy(fixedBackOffPolicy);

    //Create Simple Retry Policy
    final CmsRetryPolicy retryPolicy = new CmsRetryPolicy(Integer.valueOf(maxAttempts), Collections
            .<Class<? extends Throwable>, Boolean> singletonMap(RestClientException.class, true), false);

    //Set retry policy
    retryTemplate.setRetryPolicy(retryPolicy);
    
    //Return the RetryTemplate
    return retryTemplate;
}
 
开发者ID:sastix,项目名称:cms,代码行数:27,代码来源:RestTemplateConfiguration.java

示例12: getWithRetry

import org.springframework.retry.support.RetryTemplate; //导入依赖的package包/类
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;
	}
}
 
开发者ID:RBGKew,项目名称:powop,代码行数:22,代码来源:GetResourceClient.java

示例13: getRetryTemplate

import org.springframework.retry.support.RetryTemplate; //导入依赖的package包/类
/**
 * get a spring customized retry template
 * 
 * @param timeoutInSec
 * @return a customized retry template
 */
private static RetryTemplate getRetryTemplate(Integer timeoutInSec) {
	// we set the retry time out
	TimeoutRetryPolicy retryPolicy = new TimeoutRetryPolicy();
	retryPolicy.setTimeout(timeoutInSec * 1000 * 60);

	// we set the back off period to 60s
	FixedBackOffPolicy backOffPolicy = new FixedBackOffPolicy();
	backOffPolicy.setBackOffPeriod(60000);

	// our retry service
	RetryTemplate retryTemplate = new RetryTemplate();
	retryTemplate.setRetryPolicy(retryPolicy);
	retryTemplate.setBackOffPolicy(backOffPolicy);
	return retryTemplate;
}
 
开发者ID:orange-cloudfoundry,项目名称:elpaaso-core,代码行数:22,代码来源:EnvironmentStoriesSteps.java

示例14: getRetryTemplate

import org.springframework.retry.support.RetryTemplate; //导入依赖的package包/类
/**
 * get a spring customized retry template
 *
 * @param retryAttempts
 * @return a customized retry template
 */
private static RetryTemplate getRetryTemplate(int retryAttempts) {
    // we set the retry time out
    SimpleRetryPolicy retryPolicy = new SimpleRetryPolicy();
    retryPolicy.setMaxAttempts(retryAttempts);

    // our retry service
    RetryTemplate retryTemplate = new RetryTemplate();
    retryTemplate.setRetryPolicy(retryPolicy);
    return retryTemplate;
}
 
开发者ID:orange-cloudfoundry,项目名称:elpaaso-core,代码行数:17,代码来源:CfAdapterImpl.java

示例15: getConsul

import org.springframework.retry.support.RetryTemplate; //导入依赖的package包/类
private Consul getConsul() {
    // test that the client is active - the purpose of this test is to make sure that the instance of consul in the
    // cluster is alive, is it's not we'll create a new one before giving up. The assumption is that the hostname of
    // consul is really a consul service that hides multiple instances of consul servers.
    RetryTemplate retryTemplate = new RetryTemplate();
    retryTemplate.setBackOffPolicy(new FixedBackOffPolicy());
    TimeoutRetryPolicy retryPolicy = new TimeoutRetryPolicy();
    retryPolicy.setTimeout(10000);
    retryTemplate.setRetryPolicy(retryPolicy);

    return retryTemplate.execute(context -> {
        if (consul == null || consul.statusClient() == null || isEmpty(consul.statusClient().getLeader())) {
            // if we can't find a leader this means that the consul client is not usable - we'll release it
            log.warn("couldn't verify connection to Consul");
            log.info("creating a new Consul client");
            consul = newClient(consulProperties.getHostname(), consulProperties.getHttpPort());

            // throwing this exception to retry according to the policies. The last retry will throw this exception
            throw new IllegalStateException("Consul connection could not be verified");
        } else {
            log.info("Consul connection verified");
            return consul;
        }
    });
}
 
开发者ID:amirkibbar,项目名称:plum,代码行数:26,代码来源:Consul4Spring.java


注:本文中的org.springframework.retry.support.RetryTemplate类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。