У меня есть сервис, который использует Resilience4J для повышения устойчивости:
< pre class="lang-java Prettyprint-override">
Код: Выделить всё
@Service
class SomeService {
@RateLimiter(name = "rateLimiter")
@Retry(name = "retryTwice", fallbackMethod = "fallback")
void doSomethingImportant(int id) {
// do something important
}
void fallback(int id, Throwable throwable) {
// fallback logic
}
}
Код: Выделить всё
resilience4j.retry:
instances:
retryTwice:
maxAttempts: 2
retryExceptions:
- org.springframework.web.client.HttpServerErrorException # remote server problem
- io.github.resilience4j.ratelimiter.RequestNotPermitted # rate limit exceeded
resilience4j.ratelimiter:
limiters:
rateLimiter:
limitForPeriod: 1
limitRefreshPeriod: 1s
timeoutDuration: 3s
Код: Выделить всё
@Service
class SomeService {
/*
* Second '@Retry' annotation added, does not compile
*/
@RateLimiter(name = "rateLimiter")
@Retry(name = "retryTwice", fallbackMethod = "fallback")
@Retry(name = "retryTenTimes", fallbackMethod = "fallback")
void doSomethingImportant(int id) {
// do something important
}
void fallback(int id, Throwable throwable) {
// fallback logic
}
}
Код: Выделить всё
resilience4j.retry:
instances:
retryTwice:
maxAttempts: 2
retryExceptions:
- org.springframework.web.client.HttpServerErrorException # remote server problem
retryTenTimes:
maxAttempts: 10
retryExceptions:
- io.github.resilience4j.ratelimiter.RequestNotPermitted # rate limit exceeded
resilience4j.ratelimiter:
limiters:
rateLimiter:
limitForPeriod: 1
limitRefreshPeriod: 1s
timeoutDuration: 3s
Подробнее здесь: https://stackoverflow.com/questions/791 ... pring-boot