这一节我们来讲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.requestVolumeThreshold20 
hystrix.threadpool.[commandkey].circuitBreaker.sleepWindowInMilliseconds5000 
hystrix.threadpool.[commandkey].circuitBreaker.errorThresholdPercentage50 
hystrix.threadpool.[commandkey].circuitBreaker.forceOpenfalse 
hystrix.threadpool.[commandkey].circuitBreaker.forceClosedfalse 
hystrix.threadpool.[commandkey].execution.isolation.strategyThread 
hystrix.threadpool.[commandkey].execution.isolation.thread.timeoutInMilliseconds1000 
hystrix.threadpool.[commandkey].execution.timeout.enabledtrue 
hystrix.threadpool.[commandkey].execution.isolation.thread.interruptOnTimeouttrue 
hystrix.threadpool.[commandkey].execution.isolation.thread.interruptOnFutureCancelfalse 
hystrix.threadpool.[commandkey].execution.isolation.semaphore.maxConcurrentRequests10 
hystrix.threadpool.[commandkey].fallback.isolation.semaphore.maxConcurrentRequests10 
hystrix.threadpool.[commandkey].fallback.enabledtrue 
hystrix.threadpool.[commandkey].metrics.rollingStats.timeInMilliseconds10000 
hystrix.threadpool.[commandkey].metrics.rollingStats.numBuckets10 
hystrix.threadpool.[commandkey].metrics.rollingPercentile.enabledtrue 
hystrix.threadpool.[commandkey].metrics.rollingPercentile.timeInMilliseconds60000 
hystrix.threadpool.[commandkey].metrics.rollingPercentile.numBuckets6 
hystrix.threadpool.[commandkey].metrics.rollingPercentile.bucketSize100 
hystrix.threadpool.[commandkey].metrics.healthSnapshot.intervalInMilliseconds500 
hystrix.threadpool.[commandkey].requestCache.enabledtrue 
hystrix.threadpool.[commandkey].requestLog.enabledtrue 
hystrix.threadpool.[commandkey].threadPoolKeyOverride  
HystrixThreadPoolPropertieshystrix.threadpool.[threadPoolkey].coreSize10 
hystrix.threadpool.[threadPoolkey].allowMaximumSizeToDivergeFromCoreSizefalse 
hystrix.threadpool.[threadPoolkey].maximumSize10 
hystrix.threadpool.[threadPoolkey].keepAliveTimeMinutes1 
hystrix.threadpool.[threadPoolkey].maxQueueSize-1 
hystrix.threadpool.[threadPoolkey].queueSizeRejectionThreshold5 
hystrix.threadpool.[threadPoolkey].metrics.rollingStats.timeInMilliseconds10000 
hystrix.threadpool.[threadPoolkey].metrics.rollingStats.numBuckets10 
HystrixCollapserPropertieshystrix.collapser.[collapserCommandkey].maxRequestsInBatchInteger.MAX_VALUE 
hystrix.collapser.[collapserCommandkey].timerDelayInMilliseconds10 
hystrix.collapser.[collapserCommandkey].requestCache.enabledtrue 
hystrix.collapser.[collapserCommandkey].metrics.rollingStats.timeInMilliseconds10000 
hystrix.collapser.[collapserCommandkey].metrics.rollingStats.numBuckets10 
hystrix.collapser.[collapserCommandkey].metrics.rollingPercentile.enabledtrue 
hystrix.collapser.[collapserCommandkey].metrics.rollingPercentile.timeInMilliseconds60000 
hystrix.collapser.[collapserCommandkey].metrics.rollingPercentile.numBuckets6 
hystrix.collapser.[collapserCommandkey].metrics.rollingPercentile.bucketSize100 

  内部每个属性由一个ChainHystrixProperty表示,ChainHystrixProperty是一个串联的HystrixDynamicProperty,持续获取串中的属性值,直到获得不为null值为止。ChainHystrixProperty串联的HystrixDynamicProperty默认通过插件获取的HystrixDynamicProperties获取(最后我们会讲到插件)。

  HystrixDynamicProperty表示动态配置数据,如果配置源发送变化,通过该对象获取配置也会相应变化。hystrix中有种实现类:

    1.通过archaius实现获取配置项,通过HystrixDynamicPropertiesArchaius创建该类HystrixDynamicProperty。

    2.通过system实现获取配置项,通过HystrixDynamicPropertiesSystemProperties创建该类HystrixDynamicProperty。

05-28 23:24