使用org.springframework.retry.annotation.CircuitBreaker
和org.springframework.retry.annotation.Recover
处理后备时。当我们用一个事务测试实现时,电路就可以正确地打开和关闭。
但是,当事务负载很高时。打开的电路没有关闭。它在整个加载过程中保持打开状态。下面是我们的实现。
@CircuitBreaker(value=RedisConnectionFailureException.class, maxAttempts=1)
public String getDataFromRedisCache(String dataKey) {
// get data from cache
}
@Recover
public String fallbackToDb(RedisConnectionFailureException rcfe, String dataKey) {
// fetch from Db
}