0,User Guid
https://github.com/Netflix/Hystrix/tree/master/hystrix-contrib/hystrix-javanica#fallback
1,需要AOP引入
import com.netflix.hystrix.contrib.javanica.aop.aspectj.HystrixCommandAspect;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
/**
* HystrixCommandAop
* Created by jinglongjun on 16/9/19.
*/
@Configuration
@EnableAspectJAutoProxy
public class HystrixCommandAop {
@Bean
public HystrixCommandAspect hystrixAspect() {
return new HystrixCommandAspect();
}
}
2,需要在外部调用方法加入注解
@HystrixCommand(commandProperties = {
@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "500")
}, fallbackMethod = "defaultCountOfTaobao")
public TradeCount countOfTaobao(User user, TradeCount tc, Boolean isBindUser) {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
注意此方法必须是外部调用,如果是内部调用,则会导致方法无效。因为是通过命令模式的切面进入的,service内部methoda调用methodb无法对methodb加入切片.
3,配置说明
@HystrixCommand(groupKey="UserGroup", commandKey = "GetUserByIdCommand",
commandProperties = {
@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "500")
},
threadPoolProperties = {
@HystrixProperty(name = "coreSize", value = "30"),
@HystrixProperty(name = "maxQueueSize", value = "101"),
@HystrixProperty(name = "keepAliveTimeMinutes", value = "2"),
@HystrixProperty(name = "queueSizeRejectionThreshold", value = "15"),
@HystrixProperty(name = "metrics.rollingStats.numBuckets", value = "12"),
@HystrixProperty(name = "metrics.rollingStats.timeInMilliseconds", value = "1440")
})