2017-03-17 2 views
0

RetryTemplate의 지연 시간을 300000 ms - 5 분에 1.1 회로 늘리 길 원합니다. 그러나 다음 시도가 30 초 지연됩니다. maxDelay가 설정되지 않은 경우 Spring retryTemplate이 너무 일찍 발생합니다.

@Bean 
CommandLineRunner runner() { 
    return (String[] a) -> { 
      scheduler.schedule(() -> { 
       try { 
        retryTemplate.execute(arg -> { 
         foo.run(); 
         return null; 
        }); 
       } catch (Exception e) { 

       } 
      }, 1 , TimeUnit.SECONDS); 
    }; 
} 

로그

@Service 
public class Foo { 
    private static final Logger log = Logger.getLogger(Foo.class); 

    @Retryable(value = Exception.class, 
      backoff = @Backoff(delay = 300000, multiplier = 1.1)) 
    public void run() throws Exception { 
     new Bar().run(); 
    } 

    @Recover 
    void recover(Exception e) { 
     log.error("e", e); 
    } 
} 

public class Bar { 
    private static final Logger log = Logger.getLogger(Bar.class); 

    public void run() throws Exception{ 
     log.info("hier"); 
     throw new Exception(); 
    } 
} 

는이 시대에 만들어진 : : 나는 그것을 사용하는 경우

2017-03-17 13:25:08.439 INFO 6500 --- [ 
2017-03-17 13:25:38.439 INFO 6500 --- [ 
2017-03-17 13:26:08.440 INFO 6500 --- [ 
2017-03-17 13:26:08.444 ERROR 6500 --- [ 

그것은 변화를하지 않는 다음은 간단한 예입니다 스케줄러의 유무에 관계없이 (원래 코드가 초기 지연을 필요로하기 때문에 거기에 있습니다.)

는 지금은 그것은 의도 한대로 정확히 작동 @Backoff

@Backoff(delay = 300000, multiplier = 1.1, maxDelay = 1000000000) 

에 maxDelay를 추가하는 경우 - 5 * 1.1 분 등 후 다음 5 분 후에 발사. 그러나 @Backoff를위한 JavaDoc를 읽고 - maxDelay, 그것은 0으로 기본값 말한다 및

/** 
    * The maximimum wait (in milliseconds) between retries. If less than the 
    * {@link #delay()} then ignored. 
    * 
    * @return the maximum delay between retries (default 0 = ignored) 
    */ 
    long maxDelay() default 0; 

내가 이해하지 못했다 있나요 지연 미만의 경우 무시? maxDelay의 기본값은 30 초로, javadoc이 설명하는 것과는 완전히 다릅니다. 코드 here를 참조 -

중고 스프링 재시 버전은 1.1.3

답변

1

그것은이의 javadoc의 버그입니다.

policy.setMaxInterval(max > min ? max : ExponentialBackOffPolicy.DEFAULT_MAX_INTERVAL); 

public static final long DEFAULT_MAX_INTERVAL = 30000L; 
+0

은 지워 그 .. 감사합니다! – baao