@Retryable

2020. 11. 17. 15:02OpenSource/Spring

반응형

특정 Exception이 발생하면 일정 횟수만큼 재시도 할 수 있는 어노테이션이다.

 

  • @EnableRetry 작성.(configuration 등)
  • 재시도 하고 싶은 메소드에 @Retryable 작성. 
    • include : 특정 Exception이 발생할 때 retry
    • exclude : 설정 된 Exception 재시도 제외
    • maxAttempts : 최대 재시도 횟수(default 3회)
    • backoff : 재시도 pause 시간

ex)  FailedStoreException 발생 시 최대 5번 시도! delay 10

@Retryable(value = { FailedStoreException.class }, maxAttempts = 5, backoff = @Backoff(delay = 10))

참고

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package org.springframework.retry.annotation;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Retryable {
    String interceptor() default "";

    Class<? extends Throwable>[] value() default {};

    Class<? extends Throwable>[] include() default {};

    Class<? extends Throwable>[] exclude() default {};

    String label() default "";

    boolean stateful() default false;

    int maxAttempts() default 3;

    String maxAttemptsExpression() default "";

    Backoff backoff() default @Backoff;

    String exceptionExpression() default "";
}
반응형

'OpenSource > Spring' 카테고리의 다른 글

Spring Cloud Contract  (0) 2022.08.03
Jackson Annotation Examples  (0) 2020.11.17
@PreDestory란?  (0) 2020.11.12
@PostConstruct란?  (0) 2020.11.10
Spring WebFlux  (0) 2017.04.26