本文整理汇总了Java中org.springframework.retry.support.RetryTemplate.setRetryPolicy方法的典型用法代码示例。如果您正苦于以下问题:Java RetryTemplate.setRetryPolicy方法的具体用法?Java RetryTemplate.setRetryPolicy怎么用?Java RetryTemplate.setRetryPolicy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.retry.support.RetryTemplate
的用法示例。
在下文中一共展示了RetryTemplate.setRetryPolicy方法的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;
}
});
}
示例2: 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;
}
示例3: 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;
}
示例4: 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;
}
示例5: 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;
}
示例6: 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;
}
}
示例7: 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;
}
示例8: 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;
}
}
示例9: 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;
}
示例10: 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;
}
示例11: 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;
}
});
}
示例12: execute
import org.springframework.retry.support.RetryTemplate; //导入方法依赖的package包/类
@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
RetryTemplate retryTemplate = new RetryTemplate();
SimpleRetryPolicy retryPolicy = new SimpleRetryPolicy();
retryPolicy.setMaxAttempts(3);
retryTemplate.setRetryPolicy(retryPolicy);
// HINT: 재시도 정책을 지정해서 3번까지 재시도를 수행합니다.
//
List<Discount> discounts = retryTemplate.execute(new RetryCallback<List<Discount>>() {
@Override
public List<Discount> doWithRetry(RetryContext context) throws Exception {
return discountService.getDiscounts();
}
});
discountsHolder.setDiscounts(discounts);
return RepeatStatus.FINISHED;
}
示例13: isResourcesReady
import org.springframework.retry.support.RetryTemplate; //导入方法依赖的package包/类
/**
* Ensures external dependencies are available before starting to read messages from the queue
* @return true if startup successful, false if not
*/
public boolean isResourcesReady() {
boolean isStartupOk = false;
ExponentialBackOffPolicy exponentialBackOffPolicy = getExponentialBackOffPolicy();
SimpleRetryPolicy retryPolicy = getSimpleRetryPolicy();
RetryTemplate retryTemplate = new RetryTemplate();
retryTemplate.setRetryPolicy(retryPolicy);
retryTemplate.setBackOffPolicy(exponentialBackOffPolicy);
retryTemplate.setThrowLastExceptionOnExhausted(true);
logger.info("Waiting for Author ELB to be in healthy state");
try {
isStartupOk = retryTemplate.execute(c -> {
boolean result = aemInstanceHelperService.isAuthorElbHealthy();
if(!result) //Needs to be healthy
throw new Exception("Author ELB does not appear to be in a healthy state");
return result;
});
} catch (Exception e) {
logger.error("Failed to receive healthy state from Author ELB", e);
}
return isStartupOk;
}
示例14: getRetryTemplate
import org.springframework.retry.support.RetryTemplate; //导入方法依赖的package包/类
@Bean
protected RetryTemplate getRetryTemplate(@Value("${controller.retryCount:3}") int retryCount, @Value("${controller.intial_delay:1000}") int initialDelay, @Value("${controller.maxInterval:10000}") int maxInterval) {
RetryTemplate retryTemplate = new RetryTemplate();
retryTemplate.setRetryPolicy(new SimpleRetryPolicy(retryCount, Collections.singletonMap(RestClientException.class, true)));
ExponentialBackOffPolicy backOffPolicy = new ExponentialBackOffPolicy();
backOffPolicy.setInitialInterval(initialDelay);
backOffPolicy.setMaxInterval(maxInterval);
retryTemplate.setBackOffPolicy(backOffPolicy);
retryTemplate.setThrowLastExceptionOnExhausted(true);
retryTemplate.registerListener(new DefaultListenerSupport());
return retryTemplate;
}
示例15: createRetryTemplate
import org.springframework.retry.support.RetryTemplate; //导入方法依赖的package包/类
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;
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:13,代码来源:RabbitAutoConfiguration.java