Java Code Examples for org.springframework.retry.backoff.FixedBackOffPolicy#setBackOffPeriod()

The following examples show how to use org.springframework.retry.backoff.FixedBackOffPolicy#setBackOffPeriod() . 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: HttpBlockchainEventBroadcasterTest.java    From eventeum with Apache License 2.0 6 votes vote down vote up
@Before
public void init() {
    final HttpBroadcasterSettings settings = new HttpBroadcasterSettings();
    settings.setBlockEventsUrl("http://localhost:8082/consumer/block-event");
    settings.setContractEventsUrl("http://localhost:8082/consumer/contract-event");

    RetryTemplate retryTemplate = new RetryTemplate();

    FixedBackOffPolicy fixedBackOffPolicy = new FixedBackOffPolicy();
    fixedBackOffPolicy.setBackOffPeriod(3000l);
    retryTemplate.setBackOffPolicy(fixedBackOffPolicy);

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

    underTest = new HttpBlockchainEventBroadcaster(settings, retryTemplate);
}
 
Example 2
Source File: InteractiveQueryService.java    From spring-cloud-stream-binder-kafka with Apache License 2.0 6 votes vote down vote up
/**
 * Retrieve and return a queryable store by name created in the application.
 * @param storeName name of the queryable store
 * @param storeType type of the queryable store
 * @param <T> generic queryable store
 * @return queryable store.
 */
public <T> T getQueryableStore(String storeName, QueryableStoreType<T> storeType) {

	RetryTemplate retryTemplate = new RetryTemplate();

	KafkaStreamsBinderConfigurationProperties.StateStoreRetry stateStoreRetry = this.binderConfigurationProperties.getStateStoreRetry();
	RetryPolicy retryPolicy = new SimpleRetryPolicy(stateStoreRetry.getMaxAttempts());
	FixedBackOffPolicy backOffPolicy = new FixedBackOffPolicy();
	backOffPolicy.setBackOffPeriod(stateStoreRetry.getBackoffPeriod());

	retryTemplate.setBackOffPolicy(backOffPolicy);
	retryTemplate.setRetryPolicy(retryPolicy);

	return retryTemplate.execute(context -> {
		T store = null;

		final Set<KafkaStreams> kafkaStreams = InteractiveQueryService.this.kafkaStreamsRegistry.getKafkaStreams();
		final Iterator<KafkaStreams> iterator = kafkaStreams.iterator();
		Throwable throwable = null;
		while (iterator.hasNext()) {
			try {
				store = iterator.next().store(storeName, storeType);
			}
			catch (InvalidStateStoreException e) {
				// pass through..
				throwable = e;
			}
		}
		if (store != null) {
			return store;
		}
		throw new IllegalStateException("Error when retrieving state store: j " + storeName, throwable);
	});
}
 
Example 3
Source File: RetryInterceptor.java    From mica with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static RetryTemplate createRetryTemplate(RetryPolicy policy) {
	RetryTemplate template = new RetryTemplate();
	// 重试策略
	SimpleRetryPolicy retryPolicy = new SimpleRetryPolicy();
	retryPolicy.setMaxAttempts(policy.getMaxAttempts());
	// 设置间隔策略
	FixedBackOffPolicy backOffPolicy = new FixedBackOffPolicy();
	backOffPolicy.setBackOffPeriod(policy.getSleepMillis());
	template.setRetryPolicy(retryPolicy);
	template.setBackOffPolicy(backOffPolicy);
	return template;
}
 
Example 4
Source File: ClusterScaleProcessServiceImpl.java    From cymbal with Apache License 2.0 5 votes vote down vote up
public ClusterScaleProcessServiceImpl() {
    SimpleRetryPolicy retryPolicy = new SimpleRetryPolicy(ENLARGE_MAX_ATTEMPTS);
    retryTemplate.setRetryPolicy(retryPolicy);

    // 失败后补偿策略
    FixedBackOffPolicy backOffPolicy = new FixedBackOffPolicy();
    backOffPolicy.setBackOffPeriod(MIGRATE_BACKOFF_PERIOD);
    retryTemplate.setBackOffPolicy(backOffPolicy);
}
 
Example 5
Source File: MailServiceImpl.java    From cymbal with Apache License 2.0 5 votes vote down vote up
public MailServiceImpl() {
    SimpleRetryPolicy retryPolicy = new SimpleRetryPolicy(MAIL_MAX_ATTEMPTS);
    retryTemplate.setRetryPolicy(retryPolicy);

    // 失败后补偿策略
    FixedBackOffPolicy backOffPolicy = new FixedBackOffPolicy();
    backOffPolicy.setBackOffPeriod(MAIL_BACKOFF_PERIOD);
    retryTemplate.setBackOffPolicy(backOffPolicy);
}
 
Example 6
Source File: EternalRetryTemplateConfiguration.java    From eventeum with Apache License 2.0 5 votes vote down vote up
@Bean
public RetryTemplate eternalRetryTemplate() {
    RetryTemplate retryTemplate = new RetryTemplate();

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

    AlwaysRetryPolicy retryPolicy = new AlwaysRetryPolicy();
    retryTemplate.setRetryPolicy(retryPolicy);

    return retryTemplate;
}
 
Example 7
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 8
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 9
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 10
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 11
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 12
Source File: CuratorKafkaMonitor.java    From Kafdrop with Apache License 2.0 4 votes vote down vote up
public CuratorKafkaMonitor(CuratorFramework curatorFramework,
                           CuratorKafkaMonitorProperties properties,
                           ObjectMapper objectMapper) throws Exception
{
   this.curatorFramework = curatorFramework;
   this.properties = properties;
   this.objectMapper = objectMapper;

   try
   {
      kafkaVersion = new Version(properties.getKafkaVersion());
   }
   catch (Exception ex)
   {
      throw new IllegalStateException("Invalid kafka version: " + properties.getKafkaVersion(), ex);
   }

   threadPool = new ForkJoinPool(properties.getThreadPoolSize());

   FixedBackOffPolicy backOffPolicy = new FixedBackOffPolicy();
   backOffPolicy.setBackOffPeriod(properties.getRetry().getBackoffMillis());

   final SimpleRetryPolicy retryPolicy =
      new SimpleRetryPolicy(properties.getRetry().getMaxAttempts(),
                            ImmutableMap.of(InterruptedException.class, false,
                                            Exception.class, true));

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

   cacheInitCounter.set(4);

   brokerPathCache = new PathChildrenCache(curatorFramework, ZkUtils.BrokerIdsPath(), true);
   brokerPathCache.getListenable().addListener(new BrokerListener());
   brokerPathCache.getListenable().addListener((f, e) -> {
      if (e.getType() == PathChildrenCacheEvent.Type.INITIALIZED)
      {
         cacheInitCounter.decrementAndGet();
         LOG.info("Broker cache initialized");
      }
   });
   brokerPathCache.start(StartMode.POST_INITIALIZED_EVENT);

   topicConfigPathCache = new PathChildrenCache(curatorFramework, ZkUtils.TopicConfigPath(), true);
   topicConfigPathCache.getListenable().addListener((f, e) -> {
      if (e.getType() == PathChildrenCacheEvent.Type.INITIALIZED)
      {
         cacheInitCounter.decrementAndGet();
         LOG.info("Topic configuration cache initialized");
      }
   });
   topicConfigPathCache.start(StartMode.POST_INITIALIZED_EVENT);

   topicTreeCache = new TreeCache(curatorFramework, ZkUtils.BrokerTopicsPath());
   topicTreeCache.getListenable().addListener((client, event) -> {
      if (event.getType() == TreeCacheEvent.Type.INITIALIZED)
      {
         cacheInitCounter.decrementAndGet();
         LOG.info("Topic tree cache initialized");
      }
   });
   topicTreeCache.start();

   consumerTreeCache = new TreeCache(curatorFramework, ZkUtils.ConsumersPath());
   consumerTreeCache.getListenable().addListener((client, event) -> {
      if (event.getType() == TreeCacheEvent.Type.INITIALIZED)
      {
         cacheInitCounter.decrementAndGet();
         LOG.info("Consumer tree cache initialized");
      }
   });
   consumerTreeCache.start();

   controllerNodeCache = new NodeCache(curatorFramework, ZkUtils.ControllerPath());
   controllerNodeCache.getListenable().addListener(this::updateController);
   controllerNodeCache.start(true);
   updateController();
}
 
Example 13
Source File: AmqpContextConfig.java    From sinavi-jfw with Apache License 2.0 4 votes vote down vote up
/**
 * リトライ間隔を設定し、{@link SleepingBackOffPolicy}のインスタンスを生成します。
 * @return {@link FixedBackOffPolicy}のインスタンス
 */
protected SleepingBackOffPolicy<FixedBackOffPolicy> backOffPolicy() {
    FixedBackOffPolicy policy = new FixedBackOffPolicy();
    policy.setBackOffPeriod(backOffPeriod);
    return policy;
}
 
Example 14
Source File: FixedBackoffRetryFactory.java    From tutorials with MIT License 4 votes vote down vote up
@Override
public BackOffPolicy createBackOffPolicy(String service) {
    FixedBackOffPolicy fixedBackOffPolicy = new FixedBackOffPolicy();
    fixedBackOffPolicy.setBackOffPeriod(2000);
    return fixedBackOffPolicy;
}