1 Star 0 Fork 62

魏星-小旋风/springcloud-chapter05-02

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
m
4个月前
m
4个月前
m
10个月前
m
10个月前
m
4个月前
m
10个月前
Loading...
README

springcloud-chapter05-01

介绍

第五章服务容错保护库 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
  1. 运行 Eureka Server
  2. 运行 hello-provider
  3. 运行 eureka-hystrix-client,发请求测试效果
  4. 停止 hello-provider
  5. 发请求测试效果

效果

停止 hello-provider 后的效果

Hystrix Dashboard 监控

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;
    }
}

监控效果图

空文件

简介

第5章 容错服务 教材P70,P74 展开 收起
Java
取消

发行版

暂无发行版

贡献者 (2)

全部

近期动态

4个月前推送了新的提交到 master 分支,e1b4052...1167784
10个月前推送了新的提交到 master 分支,ef2a2fe...e1b4052
10个月前推送了新的 master 分支
10个月前创建了仓库
不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wayxingwork/springcloud-chapter05-02.git
git@gitee.com:wayxingwork/springcloud-chapter05-02.git
wayxingwork
springcloud-chapter05-02
springcloud-chapter05-02
master

搜索帮助