想找个专业做网站公司,jsp环保主题网站代做,做网站链接怎么做,公司网站建设改版文章目录一、 Hystrix简介1 什么是灾难性雪崩效应2 什么是Hystrix二、 服务降级(Ribbon中)三、 服务熔断(Ribbon中)#xff08;服务降级的强化版#xff09;四、 请求缓存(Ribbon中)(不推荐)(查询频率高#xff0c;修改频率低时谨慎使用)五、 Openfeign的雪崩处理1 服务降级…
文章目录一、 Hystrix简介1 什么是灾难性雪崩效应2 什么是Hystrix二、 服务降级(Ribbon中)三、 服务熔断(Ribbon中)服务降级的强化版四、 请求缓存(Ribbon中)(不推荐)(查询频率高修改频率低时谨慎使用)五、 Openfeign的雪崩处理1 服务降级2 服务熔断六、 可视化的数据监控Hystrix-dashboard近实时监控1 Ribbon中数据监控2 openfeign 中数据监控3 可视化监控4 访问Hystrix监控数据结果一、 Hystrix简介
1 什么是灾难性雪崩效应 造成灾难性雪崩效应的原因可以简单归结为下述三种 1.服务提供者不可用。如硬件故障、程序BUG、缓存击穿、并发请求量过大等。 2.重试加大流量。如用户重试、代码重试逻辑等。 3.服务调用者不可用。如同步请求阻塞造成的资源耗尽等。 雪崩效应最终的结果就是 服务链条中的某一个服务不可用导致一系列的服务不可用最终造成服务逻辑崩溃。这种问题造成的后果往往是无法预料的。 解决灾难性雪崩效应的方式通常有降级、熔断和请求缓存。 2 什么是Hystrix Hystrix是Netflix开源的一款容错框架具有自我保护能力。为了实现容错和自我保护。 Hystrix设计目标 1、 对来自依赖的延迟和故障进行防护和控制——这些依赖通常都是通过网络访问的 2、 阻止故障的连锁反应 3、 快速失败并迅速恢复 4、 回退并优雅降级 5、 提供近实时的监控与告警 Hystrix遵循的设计原则 1、 防止任何单独的依赖耗尽资源线程 2、 过载立即切断并快速失败防止排队 3、 尽可能提供回退以保护用户免受故障 4、 使用隔离技术例如隔板泳道和断路器模式来限制任何一个依赖的影响 5、 通过近实时的指标监控和告警确保故障被及时发现 6、 通过动态修改配置属性确保故障及时恢复 7、 防止整个依赖客户端执行失败而不仅仅是网络通信 Hystrix如何实现这些设计目标 1、 使用命令模式将所有对外部服务或依赖关系的调用包装在HystrixCommand或HystrixObservableCommand对象中并将该对象放在单独的线程中执行 2、 每个依赖都维护着一个线程池或信号量线程池被耗尽则拒绝请求而不是让请求排队。 3、 记录请求成功失败超时和线程拒绝。 4、 服务错误百分比超过了阈值熔断器开关自动打开一段时间内停止对该服务的所有请求。 5、 请求失败被拒绝超时或熔断时执行降级逻辑。 6、 近实时地监控指标和配置的修改。 !-- 在Spring cloud中处理服务雪崩效应都需要依赖hystrix组件。在Application Client应用的pom文件中都需要引入下述依赖 --dependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-netflix-hystrix/artifactId/dependency二、 服务降级(Ribbon中) 降级是指当(请求超时、资源不足等情况)发生时进行服务降级处理不调用真实服务逻辑而是使用快速失败fallback方式直接返回一个托底数据保证服务链条的完整避免服务雪崩。 解决服务雪崩效应都是避免application client请求application service时出现服务调用错误或网络问题。处理手法都是在application client中实现。我们需要在application client相关工程中导入hystrix依赖信息。并在对应的启动类上增加新的注解EnableCircuitBreaker这个注解是用于开启hystrix熔断器的简言之就是让代码中的hystrix相关注解生效。 具体实现过程如下
1 修改application service 中的service代码 修改application service工程中的代码模拟超时错误。此模拟中让服务端代码返回之前休眠2000毫秒替代具体的复杂服务逻辑。 RequestMapping(/user/save)ResponseBodypublic MapString, Object save(User user){try {Thread.sleep(2000);} catch (InterruptedException e) {e.printStackTrace();}System.out.println(新增用户数据 user);MapString, Object result new HashMap();result.put(code, 200); // 返回的状态码result.put(message, 新增用户成功); // 返回的处理结果消息。return result;}
}2 application client POM依赖添加 dependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-netflix-hystrix/artifactId/dependency3 application client容错处理代码 /*** 远程方法调用。访问application service访问的地址是http://localhost:8080/user/save* HystrixCommand注解 - Hystrix容灾处理注解。当前方法做容灾处理。* 属性fallbackMethod - 如果远程调用发生问题调用本地的什么方法获取降级结果托底。*/OverrideHystrixCommand(fallbackMethod saveFallback)public MapString, Object save(User user) {// 根据服务的名称获取服务实例。服务名称就是配置文件yml中的spring.application.name// 服务实例包括这个名称的所有服务地址和端口。ServiceInstance instance this.loadBalancerClient.choose(ribbon-app-service);// 访问地址拼接StringBuilder builder new StringBuilder();builder.append(http://).append(instance.getHost()).append(:).append(instance.getPort()).append(/user/save).append(?username).append(user.getUsername()).append(password).append(user.getPassword()).append(remark).append(user.getRemark());System.out.println(本地访问地址 builder.toString());// 创建一个Rest访问客户端模板对象。RestTemplate template new RestTemplate();// 约束响应结果类型ParameterizedTypeReferenceMapString, Object responseType new ParameterizedTypeReferenceMapString, Object() {};// 远程访问application service。ResponseEntityMapString, Object response template.exchange(builder.toString(), HttpMethod.GET,null, responseType);MapString, Object result response.getBody();return result;}private MapString, Object saveFallback(User user){// 同步-异步讲user封装成message消息发送到RabbitMQ中。System.out.println(saveFallback方法执行 user);MapString, Object result new HashMap();result.put(message, 服务器忙请稍后重试);return result;}4 application client配置文件application.yml
server:port: 8081spring:application:name: ribbon-app-clienteureka:client:service-url:defaultZone: http://localhost:8761/eureka/ribbon-app-service: # 远程访问这个命名的服务ribbon: # 底层Ribbon配置NFLoadBalancerRuleClassName: com.netflix.loadbalancer.RandomRule # 就是具体的负载均衡策略类型全名# listOfServers: localhost:8080 # 多个地址用逗号分隔。hystrix: # 配置Hystrix相关信息command: # 配置HystrixCommand相关内容default: # 所有范围execution:timeout:enabled: true # 使用Hystrix作为超时判定机制isolation:thread:timeoutInMilliseconds: 1000 # 具体的超时时间5 application client启动类
package com.bjsxt.userclient;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注解外* 还会开启Hystrix相关的数据监控服务。*/
SpringBootApplication
EnableCircuitBreaker
public class RibbonAppClientApp {public static void main(String[] args) {SpringApplication.run(RibbonAppClientApp.class, args);}
}
三、 服务熔断(Ribbon中)服务降级的强化版 当一定时间内异常请求比例请求超时、网络故障、服务异常等达到阀值时启动熔断器熔断器一旦启动则会停止调用具体服务逻辑通过fallback快速返回托底数据保证服务链的完整。 熔断有自动恢复机制如当熔断器启动后每隔5秒尝试将新的请求发送给服务提供者如果服务可正常执行并返回结果则关闭熔断器服务恢复。如果仍旧调用失败则继续返回托底数据熔断器持续开启状态。 具体实现过程如下-----在服务降级的基础上只需要修改application client容错处理代码的注解-----
application client容错处理代码
/*** 远程方法调用。访问application service访问的地址是http://localhost:8080/user/save* HystrixCommand注解 - Hystrix容灾处理注解。当前方法做容灾处理。* 属性fallbackMethod - 如果远程调用发生问题调用本地的什么方法获取降级结果托底。* 属性commandProperties - 定义Hystrix容灾逻辑的具体参数。* CIRCUIT_BREAKER_REQUEST_VOLUME_THRESHOLD - 单位时间内多少个请求发生错误默认值10开启* 熔断断路由* CIRCUIT_BREAKER_ERROR_THRESHOLD_PERCENTAGE - 单位时间内错误请求百分比开启* 熔断断路由* CIRCUIT_BREAKER_SLEEP_WINDOW_IN_MILLISECONDS - 断路由开启后休眠多少毫秒默认值5000不访问* 远程服务。*/OverrideHystrixCommand(fallbackMethod saveFallback, commandProperties {HystrixProperty(nameHystrixPropertiesManager.CIRCUIT_BREAKER_REQUEST_VOLUME_THRESHOLD,value10),HystrixProperty(nameHystrixPropertiesManager.CIRCUIT_BREAKER_ERROR_THRESHOLD_PERCENTAGE,value50),HystrixProperty(nameHystrixPropertiesManager.CIRCUIT_BREAKER_SLEEP_WINDOW_IN_MILLISECONDS,value3000)})public MapString, Object save(User user) {// 根据服务的名称获取服务实例。服务名称就是配置文件yml中的spring.application.name// 服务实例包括这个名称的所有服务地址和端口。ServiceInstance instance this.loadBalancerClient.choose(ribbon-app-service);// 访问地址拼接StringBuilder builder new StringBuilder();builder.append(http://).append(instance.getHost()).append(:).append(instance.getPort()).append(/user/save).append(?username).append(user.getUsername()).append(password).append(user.getPassword()).append(remark).append(user.getRemark());System.out.println(本地访问地址 builder.toString());// 创建一个Rest访问客户端模板对象。RestTemplate template new RestTemplate();// 约束响应结果类型ParameterizedTypeReferenceMapString, Object responseType new ParameterizedTypeReferenceMapString, Object() {};// 远程访问application service。ResponseEntityMapString, Object response template.exchange(builder.toString(), HttpMethod.GET,null, responseType);MapString, Object result response.getBody();return result;}private MapString, Object saveFallback(User user){// 同步-异步讲user封装成message消息发送到RabbitMQ中。System.out.println(saveFallback方法执行 user);MapString, Object result new HashMap();result.put(message, 服务器忙请稍后重试);return result;}四、 请求缓存(Ribbon中)(不推荐)(查询频率高修改频率低时谨慎使用) 请求缓存通常意义上说就是将同样的GET请求结果缓存起来使用缓存机制如redis、mongodb提升请求响应效率。 使用请求缓存时需要注意非幂等性操作对缓存数据的影响。 请求缓存是依托某一缓存服务来实现的。在案例中使用redis作为缓存服务器那么可以使用spring-data-redis来实现redis的访问操作。 1 修改application service代码增加get和post方法
package com.bjsxt.userservice.controller;import com.bjsxt.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;import java.util.HashMap;
import java.util.Map;/*** 提供服务的控制器*/
Controller
public class UserController {GetMapping(/post)ResponseBodypublic MapString, Object post(){System.out.println(post method run);MapString, Object result new HashMap();result.put(message, post方法执行成功);return result;}GetMapping(/get)ResponseBodypublic MapString, Object get(){System.out.println(get method run);MapString, Object result new HashMap();result.put(message, get方法执行成功);return result;}RequestMapping(/user/save)ResponseBodypublic MapString, Object save(User user){try {Thread.sleep(2000);} catch (InterruptedException e) {e.printStackTrace();}System.out.println(新增用户数据 user);MapString, Object result new HashMap();result.put(code, 200); // 返回的状态码result.put(message, 新增用户成功); // 返回的处理结果消息。return result;}
}
2 application client POM依赖添加 dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-data-redis/artifactId/dependency3 application client 容错处理代码
package com.bjsxt.userclient.service.impl;import com.bjsxt.entity.User;
import com.bjsxt.userclient.service.UserService;
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 com.netflix.loadbalancer.RandomRule;
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;import java.util.HashMap;
import java.util.Map;/*** cacheNames - 可以实现缓存分组是Hystrix做分组。* * CacheConfig(cacheNames test_cache_names)* 在类上增加CacheConfig注解用来描述当前类型可能使用cache缓存。* 如果使用缓存则缓存数据的key的前缀是cacheNames。* cacheNames是用来定义一个缓存集的前缀命名的相当于分组。*/
Service
CacheConfig(cacheNames test_cache_names)
public class UserServiceImpl implements UserService {Autowiredprivate LoadBalancerClient loadBalancerClient;/*** 查询只要路径和参数不变理论上查询结果不变。可以缓存提升查询效率。* return*/Cacheable(springcloud_cache)public MapString, Object get(){ServiceInstance instance this.loadBalancerClient.choose(ribbon-app-service);StringBuilder builder new StringBuilder();builder.append(http://).append(instance.getHost()).append(:).append(instance.getPort()).append(/get);System.out.println(builder.toString());RestTemplate template new RestTemplate();ParameterizedTypeReferenceMapString, Object type new ParameterizedTypeReferenceMapString, Object() {};ResponseEntityMapString, Object responseEntity template.exchange(builder.toString(), HttpMethod.GET, null, type);return responseEntity.getBody();}/*** 写操作数据写操作执行后缓存数据失效应该清理缓存。* return*/CacheEvict(springcloud_cache)public MapString, Object post(){ServiceInstance instance this.loadBalancerClient.choose(ribbon-app-service);StringBuilder builder new StringBuilder();builder.append(http://).append(instance.getHost()).append(:).append(instance.getPort()).append(/post);System.out.println(builder.toString());RestTemplate template new RestTemplate();ParameterizedTypeReferenceMapString, Object type new ParameterizedTypeReferenceMapString, Object() {};ResponseEntityMapString, Object responseEntity template.exchange(builder.toString(), HttpMethod.GET, null, type);return responseEntity.getBody();}
}
4 application client 配置文件application.yml
server:port: 8082spring:application:name: ribbon-app-clientredis: # spring-data-redis配置信息host: 192.168.14.129 # 访问的redis地址 默认localhostport: 6379 # redis的端口默认6379database: 0 # 访问的redis的数据库编号 默认0eureka:client:service-url:defaultZone:- http://localhost:8761/eureka/ribbon-app-service: # 远程访问这个命名的服务ribbon: # 底层Ribbon配置NFLoadBalancerRuleClassName: com.netflix.loadbalancer.RandomRule # 就是具体的负载均衡策略类型全名# listOfServers: localhost:8080 # 多个地址用逗号分隔。hystrix: # 配置Hystrix相关信息command: # 配置HystrixCommand相关内容default: # 所有范围execution:timeout:enabled: true # 使用Hystrix作为超时判定机制isolation:thread:timeoutInMilliseconds: 1000 # 具体的超时时间5 application client 启动类加EnableCaching注解
package com.bjsxt.userclient;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注解外* 还会开启Hystrix相关的数据监控服务。*/
SpringBootApplication
EnableCircuitBreaker
EnableCaching
public class RibbonAppClientApp {public static void main(String[] args) {SpringApplication.run(RibbonAppClientApp.class, args);}
}
五、 Openfeign的雪崩处理 在声明式远程服务调用Openfeign中实现服务灾难性雪崩效应处理也是通过Hystrix实现的。而feign启动器spring-cloud-starter-openfeign中是包含Hystrix相关依赖的。如果只使用服务降级功能不需要做独立依赖。如果需要使用Hystrix其他服务容错能力需要依赖spring-cloud-starter-netflix-hystrix资源。从Dalston版本后feign默认关闭Hystrix支持。所以必须在全局配置文件中开启feign技术中的Hystrix支持。具体实现如下 1 服务降级
1.1 POM依赖 Openfeign的启动器依赖spring-cloud-starter-openfeign中自带Hystrix处理相关依赖如果只使用服务降级功能不需要做独立依赖通过配置即可开启容错处理机制。 dependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-openfeign/artifactId
/dependency
dependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-netflix-hystrix/artifactId
/dependency1.2 application client 服务接口
package com.bjsxt.feign.client.service;import com.bjsxt.feign.api.UserServiceAPI;
import com.bjsxt.feign.client.service.impl.UserServiceImpl;
import org.springframework.cloud.openfeign.FeignClient;/*** 本地服务是用于远程访问Application Service的本地服务接口。*/
FeignClient(valuefeign-app-service, fallback UserServiceImpl.class)
public interface UserService extends UserServiceAPI {
}
1.3 application client 服务接口实现
package com.bjsxt.feign.client.service.impl;import com.bjsxt.feign.client.service.UserService;
import com.bjsxt.feign.entity.User;
import com.netflix.hystrix.contrib.javanica.conf.HystrixPropertiesManager;
import org.springframework.stereotype.Service;import java.util.HashMap;
import java.util.Map;/*** 本地接口的实现类* 实现类中的每个方法都是其对应的远程调用服务的降级方法。*/
Service
public class UserServiceImpl implements UserService {Overridepublic MapString, Object saveUser(User user) {MapString, Object result new HashMap();result.put(message, saveUser方法容错处理。);return result;}Overridepublic MapString, Object updateUser(User user) {MapString, Object result new HashMap();result.put(message, updateUser方法容错处理。);return result;}
}
1.4 application client 配置文件application.yml 添加
超时管理默认ribbon管理使用hystrix后由hystrix管理所以还需配置超时管理
feign:hystrix:enabled: truehystrix:command:default:execution:timeout:enable: trueisolation:thread:timeoutInMilliseconds: 10001.5 applicaiton client 启动类不需要改
package com.bjsxt.feign.client;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
import org.springframework.cloud.openfeign.EnableFeignClients;/*** 需要提供一个新的注解* EnableFeignClients - 开启OpenFeign客户端技术。扫描FeignClient注解。* 默认扫描当前类所在包及子包中所有的类型。**/
SpringBootApplication
EnableCircuitBreaker
EnableFeignClients(basePackages {com.bjsxt.feign.client.service})
public class FeignClientApp {public static void main(String[] args) {SpringApplication.run(FeignClientApp.class, args);}
}
2 服务熔断
服务降级的升级版只需要在服务降级的基础上修改配置文件即可
hystrix:command:default:execution:timeout:enable: trueisolation:thread:timeoutInMilliseconds: 1000fallback:enable: true # 是否开启服务降级处理。默认开启。circuitBreaker:enable: true # 是否开启熔断机制。 默认开启。requestVolumeThreshold: 3 # 单位时间内错误多少次请求开启熔断sleepWindowInMilliseconds: 3000 # 开启熔断口多少毫秒不访问远程服务errorThresholdPercentage: 50 # 单位时间内错误率达到多少开启熔断forceOpen: false # 是否强制开启熔断永远不访问远程服务。默认falseforceClosed: false # 是否强制关闭熔断永远访问远程服务。默认false六、 可视化的数据监控Hystrix-dashboard近实时监控 Hystrix Dashboard是一款针对Hystrix进行实时监控的工具通过Hystrix Dashboard我们可以在直观地看到各Hystrix Command的请求响应时间, 请求成功率等数据。 1 Ribbon中数据监控
1.1 POM依赖 Hystrix Dashboard是针对Hystrix容错处理相关数据的监控工具。只要在使用了Hystrix技术的应用工程中导入对应依赖即可。 注意 如果在Openfeign技术中开启Hystrix Dashboard监控则需要将spring-cloud-starter-netflix-hystrix启动器导入POM文件否则无法在启动类上使用EnableCircuitBreaker注解。 启动类上必须使用EnableCircuitBreaker注解 dependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-netflix-hystrix/artifactId
/dependency
!-- cloud中监控数据是使用boot提供的actuator实现的。 --
dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-actuator/artifactId
/dependency
dependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-netflix-hystrix-dashboard/artifactId
/dependency1.2 配置文件application.yml
management:endpoints:web:exposure:include:- info- health- hystrix.stream1.3 启动类 localhost:8080/actuator查看localhost:8080/actuator/hystrix.stream
package com.bjsxt.userclient;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;/*** 如果要使用Hystrix Dashboard做近实时监控的话启动类上必须使用EnableCircuitBreaker* 注解描述。* EnableCircuitBreaker注解除了开启Hystrix容灾处理机制扫描HystrixCommand注解外* 还会开启Hystrix相关的数据监控服务。*/
SpringBootApplication
EnableCircuitBreaker
EnableCaching
public class RibbonAppClientApp {public static void main(String[] args) {SpringApplication.run(RibbonAppClientApp.class, args);}
}
2 openfeign 中数据监控
2.1 POM依赖
dependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-netflix-hystrix/artifactId
/dependency
!-- cloud中监控数据是使用boot提供的actuator实现的。 --
dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-actuator/artifactId
/dependency
dependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-netflix-hystrix-dashboard/artifactId
/dependency2.2 application.yml 配置
management:endpoints:web:exposure:include:- info- health- hystrix.stream2.3 启动类加 EnableCircuitBreaker注解 localhost:8080/actuator查看localhost:8080/actuator/hystrix.stream
package com.bjsxt.feign.client;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
import org.springframework.cloud.openfeign.EnableFeignClients;/*** 需要提供一个新的注解* EnableFeignClients - 开启OpenFeign客户端技术。扫描FeignClient注解。* 默认扫描当前类所在包及子包中所有的类型。** EnableHystrixDashboard注解 - 开启HystrixDashboard提供的可视化界面。*/
SpringBootApplication
EnableCircuitBreaker
EnableFeignClients(basePackages {com.bjsxt.feign.client.service})
public class FeignClientApp {public static void main(String[] args) {SpringApplication.run(FeignClientApp.class, args);}
}
3 可视化监控
3.1 启动类加 EnableHystrixDashboard注解 localhost:8081/hystrix 查看
package com.bjsxt.feign.client;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
import org.springframework.cloud.openfeign.EnableFeignClients;/*** 需要提供一个新的注解* EnableFeignClients - 开启OpenFeign客户端技术。扫描FeignClient注解。* 默认扫描当前类所在包及子包中所有的类型。** EnableHystrixDashboard注解 - 开启HystrixDashboard提供的可视化界面。*/
SpringBootApplication
EnableCircuitBreaker
EnableHystrixDashboard
EnableFeignClients(basePackages {com.bjsxt.feign.client.service})
public class FeignClientApp {public static void main(String[] args) {SpringApplication.run(FeignClientApp.class, args);}
}
4 访问Hystrix监控数据结果
通过浏览器访问提供监控访问路径的应用具体地址为 http://ip:port/actuator/hystrix.stream
得到的监控结果如下 这种监控数据的获取都是JSON数据。且数据量级较大。不易于查看。可以使用Hystrix Dashboard提供的视图界面来观察监控结果。视图界面访问路径为 http://ip:port/hystrix。 进入后的监控视图界面具体含义如下