github https://github.com/Netflix/Hystrix (基本原理)
https://github.com/Netflix/Hystrix/tree/master/hystrix-contrib/hystrix-javanica (用注解写Htstrix)
spring文档 http://projects.spring.io/spring-cloud/spring-cloud.html#_spring_cloud_netflix
简单的例子 https://eacdy.gitbooks.io/spring-cloud-book/content/2%20Spring%20Cloud/2.4.2%20Hystrix%20Dashboard.html
知乎 https://zhuanlan.zhihu.com/p/26426835
cache 和 config 的写法见 https://github.com/Netflix/Hystrix/tree/master/hystrix-contrib/hystrix-javanica
@CacheRemove(commandKey = "getUserById") @HystrixCommand public void update(@CacheKey("id") User user) { storage.put(user.getId(), user); }
@CacheResult @HystrixCommand public void getUserByProfileName(@CacheKey("profile.email") User user) { storage.getUserByProfileName(user.getProfile().getName()); }添加缓存和删除缓存,id指的是user的id属性,profile.email指的是user的profile属性的email属性
public class UserService { @CacheResult @HystrixCommand public User getUserById(@CacheKey String id) { // GET return storage.get(id); } @CacheRemove(commandKey = "getUserById") @HystrixCommand public void update(@CacheKey("id") User user) { // SET storage.put(user.getId(), user); } }缓存的get和set的用法
通过设置分组HystrixCommandGroupKey 来给所有的command分组,同组的command默认使用相同的线程池
command有四种获取结果的方式,单一的结果execute,异步的结果queue,多个结果toObservable/observe(返回observable发射源)
相应的fallback也可以设置成异步和同步