Hystrix源码
2020-07-15 10:37:29 2 举报
Hystrix主流程源码
作者其他创作
大纲/内容
释放失败
Always
toObservable()
circuitBreaker.markSuccess()
onNext
execution.doOnNext(markEmits) .doOnCompleted(markOnCompleted) .onErrorResumeNext(handleFallback) .doOnEach(setRequestContext);
terminateCommandCleanup
@EnableCircuitBreaker自动装配HystrixCircuitBreakerConfiguration
维护HystrixCommandMetrics
if (circuitBreaker.attemptExecution())
healthCountsStream
getUserExecutionObservable
methodsAnnotatedWithHystrixCommand()
HystrixShutdownHook
被观察者建立关联注册
invokable = HystrixCommandFactory.getInstance().create(metaHolder);
关闭默认时长,开始尝试关闭
metrics.getHealthCountsStream()
handleShortCircuitViaFallback
spring-cloud-starter-netflix-hystrixspring-cloud-netflix-core
circuitBreaker.markNonSuccess()
否
已经初始化了的HystrixCircuitBreakerImpl断路器实现
关闭
和Sentinel相似,也用到了滑动时间窗口设计
大量的Reactor编程代码感觉不太好理解和维护类似Python中的函数式编程RxJava,观察者模式
applyHystrixSemantics
初始化订阅
Observable.defer()
GenericCommand
释放请求成功
fireOnCompletedHook
subscribeOn()
HystrixCommandexecute()
线程池threadPool.getScheduler
熔断降级限流、线程隔离信号量/线程池断路器核心注解@HystrixCommand
HystrixCommandAspect@Aspect@Pointcut@Around
失败(开关阈值)
unsubscribeCommandCleanup
run()执行正常逻辑
时间窗口内 失败请求次数/总求情数
executeCommandWithSpecifiedIsolation
观察者回调方法
注解参数@HystrixCommand
metrics.resetStream()
applyHystrixSemantics()
queue().get()
final Future<R> delegate = toObservable().toBlocking().toFuture();
是
打开
executeCommandAndObserve
HasFeatures
AbstractCommand构造方法
markOnCompleted
wrapWithAllOnNextHooks
断路器状态
MetaHolder metaHolder = metaHolderFactory.create(joinPoint);
toBlocking().toFuture()
handleFallback
getFallback()
信号量TryableSemaphore executionSemaphore = getExecutionSemaphore()
subscribeToStream
半开
0 条评论
下一页