Hystrix的笔记

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也可以设置成异步和同步  



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值