Hystrix 熔断器使用分析

2017/05/11 Blog

对于一般的try…catch可以处理的异常service,这种可直接认定服务不可用,这种可以不用hystrix。 当前端流量很大造成的timeout,必须采用hystrix降级。

Hystrix How it works

Hystrix 源码分析

待续

Hystrix dashboard

待续

Hystrisx javanica

  • pom dependency
<dependency>
    <groupId>com.netflix.hystrix</groupId>
    <artifactId>hystrix-javanica</artifactId>
    <version>1.5.10</version>
</dependency>
  • aspectj拦截注解
<aop:aspectj-autoproxy proxy-target-class="true"/>
	
<!-- hystrix -->
<bean id="hystrixAspect" class="com.netflix.hystrix.contrib.javanica.aop.aspectj.HystrixCommandAspect" />
  • 代码示例:
@HystrixCommand(fallbackMethod = "defaultNextId")
@Override
public String nextId() {
	String nextId = null;
	try{
		nextId = elasticSequence.nextId();
	}catch(Exception e){
		logger.error("原生订单号产生错误,错误是{}", e);
		throw e;
	}
	
	logger.info("nextID is {}", nextId);
	return nextId;
}

private String defaultNextId() {
	return Sequence.nextId();
}

Search

    Post Directory