hystrix(4) properties配置

这一节我们来讲hystrix的properties配置体系,properties配置也是各个功能模块的基础功能。hystrix将配置分成三个部分:

  1.HystrixCommandProperties用于HystrixCommand配置,一个HystrixCommandKey对应一个HystrixCommandProperties实例。

  2.HystrixThreadPoolProperties用于HystrixThreadPool配置,一个HystrixThreadPoolKey对应一个HystrixThreadPoolProperties实例。

  3.HystrixCollapserProperties用于HystrixCollapserCommand配置,一个HystrixCollapserKey对应一个HystrixCollapserProperties实例。

类别 配置项 默认值 说明
HystrixCommandProperties                       

hystrix.threadpool.[commandkey].circuitBreaker.enabled

true  
hystrix.threadpool.[commandkey].circuitBreaker.requestVolumeThreshold 20  
hystrix.threadpool.[commandkey].circuitBreaker.sleepWindowInMilliseconds 5000  
hystrix.threadpool.[commandkey].circuitBreaker.errorThresholdPercentage 50  
hystrix.threadpool.[commandkey].circuitBreaker.forceOpen false  
hystrix.threadpool.[commandkey].circuitBreaker.forceClosed false  
hystrix.threadpool.[commandkey].execution.isolation.strategy Thread  
hystrix.threadpool.[commandkey].execution.isolation.thread.timeoutInMilliseconds 1000  
hystrix.threadpool.[commandkey].execution.timeout.enabled true  
hystrix.threadpool.[commandkey].execution.isolation.thread.interruptOnTimeout true  
hystrix.threadpool.[commandkey].execution.isolation.thread.interruptOnFutureCancel false  
hystrix.threadpool.[commandkey].execution.isolation.semaphore.maxConcurrentRequests 10  
hystrix.threadpool.[commandkey].fallback.isolation.semaphore.maxConcurrentRequests 10  
hystrix.threadpool.[commandkey].fallback.enabled true  
hystrix.threadpool.[commandkey].metrics.rollingStats.timeInMilliseconds 10000  
hystrix.threadpool.[commandkey].metrics.rollingStats.numBuckets 10  
hystrix.threadpool.[commandkey].metrics.rollingPercentile.enabled true  
hystrix.threadpool.[commandkey].metrics.rollingPercentile.timeInMilliseconds 60000  
hystrix.threadpool.[commandkey].metrics.rollingPercentile.numBuckets 6  
hystrix.threadpool.[commandkey].metrics.rollingPercentile.bucketSize 100  
hystrix.threadpool.[commandkey].metrics.healthSnapshot.intervalInMilliseconds 500  
hystrix.threadpool.[commandkey].requestCache.enabled true  
hystrix.threadpool.[commandkey].requestLog.enabled true  
hystrix.threadpool.[commandkey].threadPoolKeyOverride    
HystrixThreadPoolProperties hystrix.threadpool.[threadPoolkey].coreSize 10  
hystrix.threadpool.[threadPoolkey].allowMaximumSizeToDivergeFromCoreSize false  
hystrix.threadpool.[threadPoolkey].maximumSize 10  
hystrix.threadpool.[threadPoolkey].keepAliveTimeMinutes 1  
hystrix.threadpool.[threadPoolkey].maxQueueSize -1  
hystrix.threadpool.[threadPoolkey].queueSizeRejectionThreshold 5  
hystrix.threadpool.[threadPoolkey].metrics.rollingStats.timeInMilliseconds 10000  
hystrix.threadpool.[threadPoolkey].metrics.rollingStats.numBuckets 10  
HystrixCollapserProperties hystrix.collapser.[collapserCommandkey].maxRequestsInBatch Integer.MAX_VALUE  
hystrix.collapser.[collapserCommandkey].timerDelayInMilliseconds 10  
hystrix.collapser.[collapserCommandkey].requestCache.enabled true  
hystrix.collapser.[collapserCommandkey].metrics.rollingStats.timeInMilliseconds 10000  
hystrix.collapser.[collapserCommandkey].metrics.rollingStats.numBuckets 10  
hystrix.collapser.[collapserCommandkey].metrics.rollingPercentile.enabled true  
hystrix.collapser.[collapserCommandkey].metrics.rollingPercentile.timeInMilliseconds 60000  
hystrix.collapser.[collapserCommandkey].metrics.rollingPercentile.numBuckets 6  
hystrix.collapser.[collapserCommandkey].metrics.rollingPercentile.bucketSize 100  

  内部每个属性由一个HystrixProperty对象表示,使用ChainProperty。而ChainProperty串联的HystrixDynamicProperty通过插件获取的HystrixDynamicProperties获取。

  HystrixProperty接口定义了一个hystrix property的获取方法;

public T get(); 

  HystrixDynamicProperty继承HystrixProperty,表示动态更新配置数据。

复制代码
public interface HystrixDynamicProperty<T> extends HystrixProperty<T>{
    
    public String getName();
    
    public void addCallback(Runnable callback);
    
}
复制代码

  ArchaiusDynamicProperty是HystrixDynamicProperty的实现类,底层通过archaius实现。

  ChainHystrixProperty是HystrixDynamicProperty的实现类,可以串联HystrixDynamicProperty,持续获取串中的属性值,直到获得不为null值为止。

  HystrixDynamicProperties定义了获取HystrixProperty的方法;HystrixDynamicPropertiesArchaius是其实现类,通过archaius实现,将PropertyWrapper封装成HystrixDynamicProperty,通过PropertyWrapper获取配置信息。

  HystrixPropertiesFactory获取HystrixCommandProperties,HystrixCollapserProperties,HystrixThreadPoolProperties,HystrixTimerThreadPoolProperties的工厂,内部通过HystrixMetricsPublisher插件获取。 

猜你喜欢

转载自www.cnblogs.com/zhangwanhua/p/10037401.html