6 Mart 2023 Pazartesi

SpringRetry UniformRandomBackOffPolicy Sınıfı

Örnek
Şöyle yaparız
import org.springframework.retry.RetryPolicy;
import org.springframework.retry.backoff.BackOffPolicy;
import org.springframework.retry.backoff.UniformRandomBackOffPolicy;
import org.springframework.retry.support.RetryTemplate;

public class PayApiRetryTemplate extends RetryTemplate implements InitializingBean {

  @Override
  public void afterPropertiesSet() throws Exception {
    this.setBackOffPolicy(backOffPolicyWithJitter());
    this.setRetryPolicy(...);
  }

  private BackOffPolicy backOffPolicyWithJitter() {
    UniformRandomBackOffPolicy policy = new UniformRandomBackOffPolicy();
    policy.setMaxBackOffPeriod(this.prop.getRetry().getMaxBackoff());
    policy.setMinBackOffPeriod(this.prop.getRetry().getMinBackoff());
    return policy;
  }
}

Hiç yorum yok:

Yorum Gönder