43. Hystrix熔断器加入

简介:

1. pom.xml中加入

1
2
3
4
< dependency >
     < groupId >org.springframework.cloud</ groupId >
     < artifactId >spring-cloud-starter-hystrix</ artifactId >
</ dependency >


2. application.properties里面加入eureka配置

1
eureka.client.serviceUrl.defaultZone=http://host:port/eureka/


2. Application.java加入注解

@EnableCircuitBreaker,@EnableEurekaClient, @EnableDiscoveryClient

1
2
3
4
5
6
@EnableCircuitBreaker
@EnableDiscoveryClient
@EnableEurekaClient
public  class  SmartHomeAuthServiceMain {
 
}


3. 具体接口前加入回滚方法

1
2
3
4
5
6
7
8
9
10
11
@HystrixCommand (fallbackMethod =  "findOrderFallback" , commandProperties = {
             @HystrixProperty (name =  "execution.isolation.thread.timeoutInMilliseconds" , value =  "2000" )
     })
public  String authPublishMessage( @RequestBody  InnerAuthPublishMessageModel requestParas) {
 
}    
 
 
public  String findOrderFallback(InnerAuthPublishMessageModel requestParas) {
         return  "failed"
}


回滚方法findOrderFallback参数和返回值和之前的一样


4. github配置文档

https://github.com/Netflix/Hystrix/wiki/Configuration




     本文转自rongwei84n 51CTO博客,原文链接:http://blog.51cto.com/483181/1983571,如需转载请自行联系原作者

相关文章
|
1月前
服务熔断器-Hystrix
服务熔断器-Hystrix
30 2
|
8月前
|
Java 机器人 Maven
【Java用法】微服务之间的相互调用方式之一,通过FeignClient客户端调用其他微服务的方法包含熔断器(Hystrix)
【Java用法】微服务之间的相互调用方式之一,通过FeignClient客户端调用其他微服务的方法包含熔断器(Hystrix)
110 0
|
1月前
|
Java Sentinel
【熔断限流组件resilience4j和hystrix】
【熔断限流组件resilience4j和hystrix】
101 0
|
4天前
springCloud之服务降级熔断Hystrix、OpenFeign
springCloud之服务降级熔断Hystrix、OpenFeign
9 0
|
1月前
|
监控 微服务
Hystrix熔断器设计思想(学习笔记)附(服务监控hystrixDashboard识图)
Hystrix熔断器设计思想(学习笔记)附(服务监控hystrixDashboard识图)
26 0
|
10月前
Ribbon、Feign、Hystrix超时&重试&熔断问题
在使用Ribbon、Feign、Hystrix组合时,因为配置的问题出现以下现象,让我的大脑CPU烧的不行不行(拿我老家话说就是“脑子ran滴奥”)
121 0
|
1月前
|
监控 Java Sentinel
springcloud4-服务熔断hystrix及sentinel
springcloud4-服务熔断hystrix及sentinel
30 0
|
1月前
|
监控 负载均衡 数据可视化
SpringCloud - Hystrix断路器-服务熔断与降级和HystrixDashboard
SpringCloud - Hystrix断路器-服务熔断与降级和HystrixDashboard
36 0
|
1月前
|
监控 数据可视化 Java
【使用Hystrix实现服务容错和熔断】—— 每天一点小知识
【使用Hystrix实现服务容错和熔断】—— 每天一点小知识
|
9月前
|
负载均衡 Java 调度
Hystrix和Sentinel熔断降级设计理念
Hystrix和Sentinel熔断降级设计理念
89 0