spring cloud resilience4j-retry 重试

Spring Cloud Resilience4j组件介绍
博客介绍了Spring Cloud Resilience4j相关内容,包括参数说明、配置文件和代码。阐述了组件执行顺序,Retry最后执行。还提及了spring cloud resilience4j - retry重试、Bulkhead线程隔离并发控制、CircuitBreaker熔断器、RateLimiter流控等功能。

参数说明

属性默认值说明
maxAttempts3最大重试次数(包含最初的第一次调用)
waitDuration500[ms]固定的重试间隔
intervalFunctionnumOfAttempts -> waitDuration计算重试等待时间的函数,默认为固定值
retryOnResultPredicateresult -> false配置某个结果是否要重试
retryOnExceptionPredicatethrowable -> true配置某个异常是否要重试
retryExceptionsempty要重试的异常列表,包含子类型
ignoreExceptionsempty忽略的异常列表,包含子类型

配置文件

resilience4j.retry:
    instances:
        backendA:
            maxRetryAttempts: 3
            waitDuration: 10s
            enableExponentialBackoff: true
            exponentialBackoffMultiplier: 2
            retryExceptions:
                - org.springframework.web.client.HttpServerErrorException
                - java.io.IOException
            ignoreExceptions:
                - io.github.robwin.exception.BusinessException
        backendB:
            maxRetryAttempts: 3
            waitDuration: 10s
            retryExceptions:
                - org.springframework.web.client.HttpServerErrorException
                - java.io.IOException
            ignoreExceptions:
                - io.github.robwin.exception.BusinessException

代码

@CircuitBreaker(name = "backendA", fallbackMethod = "fallback")
@RateLimiter(name = "backendA")
@Bulkhead(name = "backendA")
@Retry(name = "backendA", fallbackMethod = "fallback")
@TimeLimiter(name = "backendA")
public Mono<String> method(String param1) {
    return Mono.error(new NumberFormatException());
}

private Mono<String> fallback(String param1, IllegalArgumentException e) {
    return Mono.just("test");
}

private Mono<String> fallback(String param1, RuntimeException e) {
    return Mono.just("test");
}

执行顺序:

Retry ( CircuitBreaker ( RateLimiter ( TimeLimiter ( Bulkhead ( Function ) ) ) ) )

Retry是最后执行

更多

spring cloud resilience4j-retry 重试
spring cloud resilience4j - Bulkhead 线程隔离 并发控制
spring cloud Resilience4j - 熔断器 CircuitBreaker
spring cloud resilience4j - RateLimiter 流控

https://resilience4j.readme.io/docs/retry

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

xiegwei

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值