hystrix之javanica

上一篇文章hystrix使用中讲解了使用Hystrix的基本方法,可以看出需要手写大量代码,做为一个不爱动手的程序猿当然觉得麻烦,所以Javanica诞生了。
Javanica项目通过引入支持注解,使Hystrix更容易使用:
1.添加依赖

<dependency>
  <groupId>com.netflix.hystrix</groupId>
  <artifactId>hystrix-core</artifactId>
  <version>1.5.11</version>
</dependency>
<dependency>
  <groupId>com.netflix.hystrix</groupId>
  <artifactId>hystrix-javanica</artifactId>
  <version>1.5.11</version>
</dependency>

2.添加AOP

<aop:aspectj-autoproxy/>
<bean id="hystrixAspect" class="com.netflix.hystrix.contrib.javanica.aop.aspectj.HystrixCommandAspect"></bean>

3.添加HystrixCommand注解

public class StudentService {
...
    @HystrixCommand(groupKey= "group",
                    commandKey = "commandkey"
                    commandProperties = {
                        @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "100")})
    public Student getNameById(String id) {
        return studentResource.getNameById(id);
    }
}
...

更多配置:
execution.isolation.thread.timeoutInMilliseconds|执行超时时间|default:1000
circuitBreaker.requestVolumeThreshold|触发断路最低请求数|default:20
circuitBreaker.sleepWindowInMilliseconds|断路器恢复时间|default:5000
circuitBreaker.errorThresholdPercentage|触发短路错误率,单位%|default:50
coreSize|线程池核心数|default:10
maxQueueSize|队列长度|default:-1(SynchronousQueue)
queueSizeRejectionThreshold|队满拒绝服务阈值|default:5|此值生效优先于队满
metrics.rollingStats.timeInMilliseconds|窗口维持时间|默认10000
metrics.rollingPercentile.numBuckets|窗口拆分数|默认10

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值