你的位置:首页 > 软件开发 > Java > 第五章 服务熔断(hystrix)+ retrofit底层通信(AsyncHttpclient)

第五章 服务熔断(hystrix)+ retrofit底层通信(AsyncHttpclient)

发布时间:2016-08-04 00:00:07
一、集群容错技术选型:hystrix。(就是上图中熔断器)熔断的作用:第一个作用:假设有两台服务器server1(假设可以处理的请求阈值是1W请求)和server2,在server1上注册了三个服务service1、service2、service3,在server2上注册了一个 ...

第五章 服务熔断(hystrix)+ retrofit底层通信(AsyncHttpclient)

第五章 服务熔断(hystrix)+ retrofit底层通信(AsyncHttpclient)

 

一、集群容错

技术选型:hystrix。(就是上图中熔断器

熔断的作用

第一个作用:

假设有两台服务器server1(假设可以处理的请求阈值是1W请求)和server2,在server1上注册了三个服务service1、service2、service3,在server2上注册了一个服务service4,假设service4服务响应缓慢,service1调用service4时,一直在等待响应,那么在高并发下,很快的server1处很快就会达到请求阈值(server1很快就会耗尽处理线程)之后可能宕机,这时候,不只是service1不再可用,server1上的service2和service3也不可用了。

如果我们引入了hystrix,那么service1调用service4的时候,当发现service4超时,立即断掉不再执行,执行getFallback逻辑。这样的话,server1就不会耗尽处理线程,server1上的其他服务也是可用的。当然,这是在合理的配置了超时时间的情况下,如果超时时间设置的太长的话,还是会出现未引入hystrix之前的情况。

第二个作用:

当被调服务经常失败,比如说在10min(可配)中之内调用了20次,失败了15次(可配),那么我们认为这个服务是失败的,先关闭该服务,等一会儿后再自动重新启动该服务!(这是真正的熔断!)

 

二、实现

1、framework

第五章 服务熔断(hystrix)+ retrofit底层通信(AsyncHttpclient)

1.1、pom.

第五章 服务熔断(hystrix)+ retrofit底层通信(AsyncHttpclient)第五章 服务熔断(hystrix)+ retrofit底层通信(AsyncHttpclient)
 1     <!-- converter-jackson --> 2     <dependency> 3       <groupId>com.squareup.retrofit</groupId> 4       <artifactId>converter-jackson</artifactId> 5       <version>1.9.0</version> 6     </dependency> 7     <!-- async-http-client --> 8     <dependency> 9       <groupId>com.ning</groupId>10       <artifactId>async-http-client</artifactId>11       <version>1.9.31</version>12     </dependency>13 14     <!-- hystrix -->15     <dependency>16       <groupId>com.netflix.hystrix</groupId>17       <artifactId>hystrix-core</artifactId>18       <version>1.5.3</version>19     </dependency>20     <dependency>21       <groupId>com.netflix.hystrix</groupId>22       <artifactId>hystrix-metrics-event-stream</artifactId>23       <version>1.5.3</version>24     </dependency>

原标题:第五章 服务熔断(hystrix)+ retrofit底层通信(AsyncHttpclient)

关键词:ie

ie
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。