代码拉取完成,页面将自动刷新
第五章服务容错保护库 Hystrix
基于Feign中使用
教材P70 Feign组件包含了Hystrix 熔断功能,但需要配置启用
需要重点掌握
基于Feign实现类图
Feign客户端配置
server:
port: 8764
spring:
application:
name: eureka-hystrix-client
eureka:
client:
service-url:
defaultZone: http://localhost:7000/eureka/
instance:
hostname: localhost
feign:
hystrix:
enabled: true
停止 hello-provider 后的效果
eureka-hystrix-client 下 pom.xml 添加
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
主程序添加注解 EurekaHystrixClientApplication
@SpringBootApplication
@EnableFeignClients
@EnableEurekaClient
@EnableHystrixDashboard
public class EurekaHystrixClientApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaHystrixClientApplication.class, args);
}
}
添加配置类 HystrixDashboardConfiguration
@Configuration
public class HystrixDashboardConfiguration {
@Bean
public ServletRegistrationBean getServlet() {
HystrixMetricsStreamServlet streamServlet = new
HystrixMetricsStreamServlet();
ServletRegistrationBean registrationBean = new
ServletRegistrationBean(streamServlet);
registrationBean.setLoadOnStartup(1);
registrationBean.addUrlMappings("/hystrix.stream");
registrationBean.setName("HystrixMetricsStreamServlet");
return registrationBean;
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。