You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
761 B
38 lines
761 B
package com.soa.microservice.core;
|
|
|
|
/**
|
|
* 断路器接口
|
|
* 实现熔断器模式,防止故障级联传播
|
|
*/
|
|
public interface CircuitBreaker {
|
|
/**
|
|
* 尝试执行操作
|
|
* @return 是否允许执行
|
|
*/
|
|
boolean allowRequest();
|
|
|
|
/**
|
|
* 记录成功请求
|
|
*/
|
|
void recordSuccess();
|
|
|
|
/**
|
|
* 记录失败请求
|
|
*/
|
|
void recordFailure();
|
|
|
|
/**
|
|
* 获取当前断路器状态
|
|
* @return 断路器状态
|
|
*/
|
|
State getState();
|
|
|
|
/**
|
|
* 断路器状态枚举
|
|
*/
|
|
enum State {
|
|
CLOSED, // 关闭状态,允许请求通过
|
|
OPEN, // 打开状态,拒绝请求
|
|
HALF_OPEN // 半开状态,允许有限请求通过以探测服务是否恢复
|
|
}
|
|
} |