5、backoff重试等待策略,默认使用@Backoff,@Backoff的value默认为1000L,我们设置为2000L;multiplier(...
@ServicepublicclassRemoteService{@Retryable(value={Exception.class},maxAttempts=5,backoff=@Backoff(delay=5000L,multiplier=1))publicvoidcall(){System.out.println(LocalDateTime.now()+": do something...");thrownewRuntimeException(LocalDateTime.now()+": 运行调用异常");}@Recoverpublicvoidrecover(Exce...
@Retryable(value = Exception.class,maxAttempts = 3,backoff = @Backoff(delay = 2000,multiplier = 1.5)) public int testRetry(int code) throws Exception{ System.out.println("test被调用,时间:"+ LocalTime.now()); if (code==0){ throw new Exception("情况不对头!"); } System.out.println(...
1、引入maven依赖 2、添加@Retryable和@Recover注解 @Retryable注解,被注解的方法发生异常时会重试 value:指定发生的异常进行重试 include:和value一样,默认空,当exclude也为空时,所有异常都重试 exclude:指定异常不重试,默认空,当include也为空时,所有异常都重试 maxAttemps:重试次数,默认3 backoff:重试补偿机制,...
*/@Retryable(value = Exception.class, maxAttempts = 3, backoff = @Backoff(delay = 2000, multiplier = 1.5))publicvoidretryableRecommendRegistry(DistributionRegisterMsg msgEntity){ log.info("调用可重试的推荐注册方法:{}", JSON.toJSONString(msgEntity)); ...
*@paramcount*@return*@throwsException*/@Retryable(value={RemoteAccessException.class},maxAttempts=5,backoff=@Backoff(delay=2000,multiplier=1.5))publicStringcall(Integercount)throwsException{if(count==10){log.info("Remote RPC call do something... {}",LocalTime.now());thrownewRemoteAccessException...
1. @Retryable注解参数 value:抛出我们指定异常才会重试 include:和value一样,默认为空,当exclude也为空时,默认所有异常 exclude:指定不处理的异常 maxAttempts:最大重试次数,默认3次,包括第一次请求也算在其中 backoff:重试等待策略,默认使用@Backoff,@Backoff的value默认为1000L ...
*/@Retryable(value={RemoteAccessException.class},maxAttempts=5,backoff=@Backoff(delay=2000,multiplier=1.5))publicStringcall(Integercount)throwsException{if(count==10){log.info("Remote RPC call do something... {}",LocalTime.now());thrownewRemoteAccessException("RPC调用异常");}return"SUCCESS"...
3.在方法上添加@Retryable import com.mail.elegant.service.TestRetryService; import org.springframework.retry.annotation.Backoff; import org.springframework.retry.annotation.Retryable; import org.springframework.stereotype.Service;
如上文所说,我们需要重试的方法是retryRequestService.request这个方法。那么我们就在这个方法上加@Retryable注解。如下: @Service @Slf4j public class RetryRequestService { @Autowired private OtherSystemSpi otherSystemSpi; @Retryable(value = RuntimeException.class, maxAttempts = 5, backoff = @Backoff(de...