Hystrix熔断器:正常是一个关闭状态,触发也就是当你错误次数超过一个值时候(值可以设置),就会打开(不再提供服务)状态,相当于跳闸,但是有一个恢复时间,之后半开的状态配置一个失败率也就是之后小于这个失败率就可以进行一个全开如果超过的话就会重新打开.
造成灾难性雪崩效应的原因,可以简单归结为下述三种:
服务提供者不可用。如:硬件故障、程序 BUG、缓存击穿、并发请求量过大等。
重试加大流量。如:用户重试、代码重试逻辑等。
服务调用者不可用。如:同步请求阻塞造成的资源耗尽等。
Hystrix 设计目标:
Hystrix 遵循的设计原则:
Hystrix 如何实现这些设计目标?
在 Spring cloud 中处理服务雪崩效应,都需要依赖 hystrix 组件。在 Application Client 应用的 pom 文件中都需要引入下述依赖:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
package com.csdn.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class ServiceController {
@GetMapping
public Object first(){
try {
// 用于模拟远程服务调用延时。
Thread.sleep(2000);
}catch (InterruptedException e) {
e.printStackTrace();
}
return "测试 Spring Cloud Netflix Ribbon 开发服务提供者";
}
}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>cloudhystrix</artifactId>
<groupId>com.csdn</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>applicationclient</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
</dependencies>
</project>
package com.csdn.service.impl;
import com.csdn.service.ClientService;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
@Service
public class ClientServiceImpl implements ClientService {
@Autowired
private LoadBalancerClient loadBalancerClient;
// HystrixCommand - 开启 Hystrix 容错处理的注解。代表当前方法如果出现服务调用问题,使用 Hystrix 容错处理逻辑来处理
//属性 fallbackMethod - 如果当前方法调用服务,远程服务出现问题的时候,调用本地的哪个方法得到托底数据。
@HystrixCommand(fallbackMethod = "downgradeFallback")
@Override
public String first() {
ServiceInstance si = this.loadBalancerClient.choose("application-service");
StringBuilder sb = new StringBuilder();
sb.append("http://").append(si.getHost()).append(":").append(si.getPort()).append("/");
System.out.println("本次访问的 service 是: " + sb.toString());
RestTemplate rt = new RestTemplate();
ParameterizedTypeReference<String> type = new ParameterizedTypeReference<String>() { };
ResponseEntity<String> response = rt.exchange(sb.toString(), HttpMethod.GET, null, type);
String result = response.getBody();
return result;
}
// 本地容错方法,只有远程服务调用过程出现问题的时候,才会调用此方法,获取托底数据。保证服务完整性。
private String downgradeFallback(){
return "服务降级方法返回托底数据";
}
}
server:
port: 8082
spring:
application:
name: application-client
eureka:
client:
service-url:
defaultZone:
- http://localhost:8761/eureka/
hystrix:
command:
default:
execution:
timeout:
# 如果 enabled 设置为 false,则请求超时交给 ribbon 控制,为 true,则超时作为容错根据
enabled: true
isolation:
thread:
timeoutInMilliseconds: 1000 # 超时时间,默认 1000ms
package com.csdn;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
// @EnableCircuitBreaker - 开启 Hystrix 容错处理能力。
// 如果不使用此注解,服务代码中的@HystrixCommand 注解无效。
@SpringBootApplication
@EnableCircuitBreaker
public class ClientApp {
public static void main(String[] args) {
SpringApplication.run(ClientApp.class, args);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>cloudhystrix</artifactId>
<groupId>com.csdn</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>applicationclient</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
</dependencies>
</project>
package com.csdn.service.impl;
import com.csdn.service.ClientService;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import com.netflix.hystrix.contrib.javanica.conf.HystrixPropertiesManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
@Service
public class ClientServiceImpl implements ClientService {
@Autowired
private LoadBalancerClient loadBalancerClient;
//@HystrixCommand - 开启 Hystrix 容错处理的注解。代表当前方法如果出现服务调用问题,使用 Hystrix 容错处理逻辑来处理
//属性 fallbackMethod - 如果当前方法调用服务,远程服务出现问题的时候,调用本地的哪个方法得到托底数据
@HystrixCommand(fallbackMethod = "downgradeFallback", commandProperties = {
// 默认 20 个;10s 内请求数大于 20 个时就启动熔断器,当请求符合熔断条件时将触发 fallback 逻辑
@HystrixProperty(name = HystrixPropertiesManager.CIRCUIT_BREAKER_REQUEST_VOLUME_THRESHOLD, value = "10"),
// 请求错误率大于 50%时就熔断,然后 for 循环发起请求,当请求符合熔断 条件时将触发
@HystrixProperty(name = HystrixPropertiesManager.CIRCUIT_BREAKER_ERROR_THRESHOLD_PERCENTAGE, value = "50"),
// 默认 5 秒;熔断多少秒后去尝试请求
@HystrixProperty(name = HystrixPropertiesManager.CIRCUIT_BREAKER_SLEEP_WINDOW_IN_MILLISECONDS, value = "5000")
}
)
@Override
public String first() {
ServiceInstance si = this.loadBalancerClient.choose("application-service");
StringBuilder sb = new StringBuilder();
sb.append("http://").append(si.getHost()).append(":").append(si.getPort()).append("/");
System.out.println("本次访问的 service 是: " + sb.toString());
RestTemplate rt = new RestTemplate();
ParameterizedTypeReference<String> type = new ParameterizedTypeReference<String>() { };
ResponseEntity<String> response = rt.exchange(sb.toString(), HttpMethod.GET, null, type);
String result = response.getBody();
return result;
}
// 本地容错方法,只有远程服务调用过程出现问题的时候,才会调用此方法,获取托底数据。保证服务完整性。
private String downgradeFallback(){
return "服务降级方法返回托底数据";
}
}
server:
port: 8082
spring:
application:
name: application-client
eureka:
client:
service-url:
defaultZone:
- http://localhost:8761/eureka/
hystrix:
command:
default:
execution:
timeout:
# 如果 enabled 设置为 false,则请求超时交给 ribbon 控制,为 true,则超时作为容错根据
enabled: true
isolation:
thread:
timeoutInMilliseconds: 1000 # 超时时间,默认 1000ms
package com.csdn;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
//@EnableCircuitBreaker - 开启 Hystrix 容错处理能力。
//如果不使用此注解,服务代码中的@HystrixCommand 注解无效。
@SpringBootApplication
@EnableCircuitBreaker
public class ClientApp {
public static void main(String[] args) {
SpringApplication.run(ClientApp.class, args);
}
}
package com.csdn.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class ServiceController {
@PostMapping("/testPost")
public Object testPost(){
System.out.println("testPost method run");
return "写操作返回";
}
@GetMapping("/testGet")
public Object testGet(){
System.out.println("testGet method run");
return "读操作返回";
}
@GetMapping
public Object first(){
System.out.println("run");
try {
// 用于模拟远程服务调用延时。
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
return "测试 Spring Cloud Netflix Ribbon 开发服务提供者";
}
}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>cloudhystrix</artifactId>
<groupId>com.csdn</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>applicationclient</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
</dependencies>
</project>
package com.csdn.service.impl;
import com.csdn.service.ClientService;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import com.netflix.hystrix.contrib.javanica.conf.HystrixPropertiesManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
//在类上,增加@CacheConfig 注解,用来描述当前类型可能使用 cache 缓存。
//如果使用缓存,则缓存数据的 key 的前缀是 cacheNames。
//cacheNames 是用来定义一个缓存集的前缀命名的,相当于分组
@CacheConfig(cacheNames = "test.hystrix.caches")
@Service
public class ClientServiceImpl implements ClientService {
@Autowired
private LoadBalancerClient loadBalancerClient;
//@HystrixCommand - 开启 Hystrix 容错处理的注解。代表当前方法如果出现服务调用问题,使用 Hystrix 容错处理逻辑来处理
//属性 fallbackMethod - 如果当前方法调用服务,远程服务出现问题的时候,调用本地的哪个方法得到托底数据。
@HystrixCommand(fallbackMethod = "downgradeFallback",commandProperties = {
// 默认 20 个;10s 内请求数大于 20 个时就启动熔断器,当请求符合熔断条件时将触发 fallback 逻辑
@HystrixProperty(name = HystrixPropertiesManager.CIRCUIT_BREAKER_REQUEST_VOLUME_THRESHOLD, value = "10"),
// 请求错误率大于 50%时就熔断,然后 for 循环发起请求,当请求符合熔断条件时将触发
@HystrixProperty(name = HystrixPropertiesManager.CIRCUIT_BREAKER_ERROR_THRESHOLD_PERCENTAGE, value = "50"),
// 默认 5 秒;熔断多少秒后去尝试请求
@HystrixProperty(name = HystrixPropertiesManager.CIRCUIT_BREAKER_SLEEP_WINDOW_IN_MILLISECONDS, value = "5000")
}
)
@Override
public String first() {
ServiceInstance si = this.loadBalancerClient.choose("application-service");
StringBuilder sb = new StringBuilder();
sb.append("http://").append(si.getHost()).append(":").append(si.getPort()).append("/");
System.out.println("本次访问的 service 是: " + sb.toString());
RestTemplate rt = new RestTemplate();
ParameterizedTypeReference<String> type = new ParameterizedTypeReference<String>() { };
ResponseEntity<String> response = rt.exchange(sb.toString(), HttpMethod.GET, null, type);
String result = response.getBody();
return result;
}
//@Cacheable - 将当期方法的返回值缓存到 cache 中
//只要方法增加了@Cacheable 注解,每次调用当前方法的时候,spring cloud 都会先访问 cache 获取数据
//如果 cache 中没有数据,则访问远程服务获取数据。远程服务返回数据,先保存在 cache 中,再返回给客户端
//如果 cache 中有数据,则直接返回 cache 中的数据,不会访问远程服务。
//请求缓存会有缓存数据不一致的可能。缓存数据过期、失效、脏数据等情况。
//一旦使用了请求缓存来处理幂等性请求操作。则在非幂等性请求操作中必须管理缓存。避免缓存数据的错误。
@Override
@Cacheable("myCache")
public String testGet() {
ServiceInstance si = this.loadBalancerClient.choose("application-service");
StringBuilder sb = new StringBuilder();
sb.append("http://").append(si.getHost()).append(":").append(si.getPort()).append("/testGet");
System.out.println("本次访问的 service 是: " + sb.toString());
RestTemplate rt = new RestTemplate();
ParameterizedTypeReference<String> type = new ParameterizedTypeReference<String>() { };
ResponseEntity<String> response = rt.exchange(sb.toString(), HttpMethod.GET, null, type);
String result = response.getBody();
return result;
}
//管理缓存。根据参数 key 删除缓存中对应的缓存数据
@Override
@CacheEvict("myCache")
public String testPost() {
ServiceInstance si = this.loadBalancerClient.choose("application-service");
StringBuilder sb = new StringBuilder();
sb.append("http://").append(si.getHost()).append(":").append(si.getPort()).append("/testPost");
System.out.println("本次访问的 service 是: " + sb.toString());
RestTemplate rt = new RestTemplate();
ParameterizedTypeReference<String> type = new ParameterizedTypeReference<String>() { };
ResponseEntity<String> response = rt.exchange(sb.toString(), HttpMethod.POST, null, type);
String result = response.getBody();
return result;
}
// 本地容错方法,只有远程服务调用过程出现问题的时候,才会调用此方法,获取托底数据。保证服务完整性。
private String downgradeFallback(){
return "服务降级方法返回托底数据";
}
}
server:
port: 8082
spring:
application:
name: application-client
redis:
host: 192.168.89.129
eureka:
client:
service-url:
defaultZone:
- http://localhost:8761/eureka/
hystrix:
command:
default: # default 全局有效,service id 指定应用有效,如:application-service
execution:
timeout:
# 如果 enabled 设置为 false,则请求超时交给 ribbon 控制,为 true,则超时作为容错根据
enabled: true
isolation:
thread:
timeoutInMilliseconds: 1000 # 超时时间,默认 1000ms
package com.csdn;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
//@EnableCircuitBreaker - 开启 Hystrix 容错处理能力。
//如果不使用此注解,服务代码中的@HystrixCommand 注解无效
//EnableCaching - 开启 spring cloud 对 cache 的支持
//可以自动的使用请求缓存,访问 redis 等 cache 服务。
@EnableCaching
@SpringBootApplication
@EnableCircuitBreaker
public class ClientApp {
public static void main(String[] args) {
SpringApplication.run(ClientApp.class, args);
}
}
package com.csdn.service;
import com.csdn.service.impl.FirstClientServiceImpl;
import com.csdn.serviceapi.FirstServiceAPI;
import org.springframework.cloud.openfeign.FeignClient;
//注解属性 fallback - 当前接口远程调用服务发生问题时,使用哪一个对象中的对应方法用于实现容错逻辑
//Openfeign 技术中,容错处理是使用当前接口的实现类实现的。
//实现类中的方法实现,就是对应的容错 fallback 处理逻辑
@FeignClient(name="openfeign-service", fallback = FirstClientServiceImpl.class)
public interface FirstClientService extends FirstServiceAPI { }
package com.csdn.service.impl;
import com.csdn.entity.User;
import com.csdn.service.FirstClientService;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.List;
//当前类型的实例必须由 Spring 容器管理,需要使用@Component 注解描述。
//每个实现方法对应远程服务调用的容错处理逻辑
@Component
public class FirstClientServiceImpl implements FirstClientService {
@Override
public List<String> testFeign() {
return Arrays.asList("Openfeign 返回托底数据");
}
@Override
public User getMultiParams(Integer id, String name) {
User user = new User();
user.setId(0);
user.setUsername("托底数据");
user.setRemark("getMultiParams");
return user;
}
@Override
public User postMultiParams(Integer id, String name) {
User user = new User();
user.setId(0);
user.setUsername("托底数据");
user.setRemark("postMultiParams");
return user;
}
@Override
public User postObjectParam(User pojo) {
User user = new User();
user.setId(0);
user.setUsername("托底数据");
user.setRemark("postObjectParam");
return user;
}
}
server:
port: 8082
spring:
application:
name: openfeign-client
eureka:
client:
service-url:
- http://localhost:8761/eureka/
feign: # 开启 feign 技术中的 Hystrix 容错处理机制
hystrix:
enabled: true
hystrix:
command:
default:
execution:
timeout:
enable: true
isolation:
thread:
timeoutInMilliseconds: 1000
package com.csdn;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;
// @EnableCircuitBreaker - 在 Openfeign 开发的 application client 应用的启动类中,不需要使用此注解开启容错处理逻辑。
//Openfeign 的启动器 spring-cloud-starter-openfeign 中,依赖的是 Hystrix 相关 jar 包,不是完整的 spring-cloud-starter-netflix-hystrix 启动器。
//如果使用此注解,在启动的时候,会抛出 ClassNotFoundException。
@SpringBootApplication
@EnableFeignClients(basePackages = "com.csdn.service")
public class OpenfeignClientApp {
public static void main(String[] args) {
SpringApplication.run(OpenfeignClientApp.class, args);
}
}
server:
port: 8082
spring:
application:
name: openfeign-client
eureka:
client:
service-url:
- http://localhost:8761/eureka/
feign:
hystrix:
enabled: true
hystrix:
command:
default:
execution:
timeout:
enable: true
isolation:
thread:
timeoutInMilliseconds: 1000
fallback:
enabled: true # 当远程调用失败或者请求被拒绝,是否会尝试调用 fallback 方法 。默认 true
circuitBreaker: # 服务熔断(Circuit Breaker)相关配置属性
enabled: true # 是否开启熔断器。默认 true
requestVolumeThreshold: 20 # 默认 20 个;10s 内请求数大于 20 个时就启动熔断器,当请求符合熔断条件时将触发 fallback 逻辑
errorThresholdPercentage: 50 # 请求错误率大于 50%时就熔断,然后 for 循环发起请求,当请求符合熔断条件时将触发
sleepWindowInMilliseconds: 5000 # 默认 5 秒;熔断多少秒后去尝试请求
forceOpen: false # 是否强制打开熔断器, 默认 false
forceClosed: false # 是否强制关闭熔断器, 默认 false
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>cloudhystrix</artifactId>
<groupId>com.csdn</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>applicationclient</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency>
</dependencies>
</project>
server:
port: 8082
spring:
application:
name: application-client
redis:
host: 192.168.89.129
eureka:
client:
service-url:
defaultZone:
- http://localhost:8761/eureka/
hystrix:
command:
default: # default 全局有效,service id 指定应用有效,如:application-service
execution:
timeout:
# 如果 enabled 设置为 false,则请求超时交给 ribbon 控制,为 true,则超时作为容错根据
enabled: true
isolation:
thread:
timeoutInMilliseconds: 1000 # 超时时间,默认 1000ms
management:
endpoints:
web:
exposure:
include: # 开启的 actuator 监控路径,默认开启 info 和 health。其他需要手工增加,使用*代表开启所有监控路径。
- info
- health
- hystrix.stream
package com.csdn;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
//@EnableCircuitBreaker - 开启 Hystrix 容错处理能力。
//如果不使用此注解,服务代码中的@HystrixCommand 注解无效。
//且 Hystrix 相关监控数据无法收集。
//@EnableCaching - 开启 spring cloud 对 cache 的支持。
//可以自动的使用请求缓存,访问 redis 等 cache 服务
//@EnableHystrixDashboard - 开启 Hystrix Dashboard 监控仪表盘
@EnableHystrixDashboard
@EnableCaching
@SpringBootApplication
@EnableCircuitBreaker
public class ClientApp {
public static void main(String[] args) {
SpringApplication.run(ClientApp.class, args);
}
}
版权说明 : 本文为转载文章, 版权归原作者所有 版权申明
原文链接 : https://blog.csdn.net/ZGL_cyy/article/details/112726514
内容来源于网络,如有侵权,请联系作者删除!