开启feign 熔断 hystrix    整合hystrix-dashboard监控面板

1. 服务调用者boot工程 pom引入依赖

<!-- hystrix-dashboard 监控依赖 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
<version>2.0.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
<version>2.0.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

  

2. 启动类开启熔断注解 @EnableCircuitBreaker  面板监控注解 @EnableHystrixDashboard  添加面板servlet

@SpringBootApplication
@EnableEurekaClient
@EnableFeignClients
@EnableCircuitBreaker
@EnableHystrixDashboard
public class WebWapApplication { public static void main(String[] args) {
SpringApplication.run(WebWapApplication.class, args);
} @Bean
@LoadBalanced
RestTemplate restTemplate(){
return new RestTemplate();
} @Bean
public ServletRegistrationBean getServlet(){
HystrixMetricsStreamServlet streamServlet=new HystrixMetricsStreamServlet();
ServletRegistrationBean registrationBean=new ServletRegistrationBean(streamServlet);
registrationBean.setLoadOnStartup(1);
registrationBean.addUrlMappings("/actuator/hystrix.stream");
registrationBean.setName("HystrixMetricsStreamServlet");
return registrationBean;
} }

  

3.修改配置文件  开启feign熔断  设置超时时间

feign.hystrix.enabled=true
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=20000

  

4.浏览器查看面板监控   http://localhost:8080/hystrix

点击Monitor Stream   可查看请求成功次数   超时次数  等等

整合多个服务  分布式监控   使用 Turbine

1.新建boot工程  引入依赖

 <!-- eureka客户端  -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency> <!-- hystrix 监控面板 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency> <dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix-turbine</artifactId>
</dependency>

2.启动类添加注解

  

@SpringBootApplication
@EnableEurekaClient
@EnableHystrixDashboard
@EnableTurbine
public class HystrixDashboardApplication { public static void main(String[] args) {
SpringApplication.run(HystrixDashboardApplication.class, args);
}
@Bean
@LoadBalanced
RestTemplate restTemplate(){
return new RestTemplate();
} @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;
}
}

  

3. 配置文件

server.port=9004
spring.application.name=hystrix-dashboard
#eureka
eureka.client.service-url.defaultZone=http://localhost:9001/eureka/
eureka.instance.prefer-ip-address=true
eureka.instance.instance-id=${spring.cloud.client.ip-address}:${server.port} management.endpoints.web.exposure.include=hystrix.stream,health,info #要监控的服务name
turbine.app-config=web-wap turbine.cluster-name-expression=new String("default")
management.endpoint.health.show-details=always
management.health.redis.enabled=false

  

4.启动 查看面板

spring cloud(五) hystrix的更多相关文章

  1. Spring Cloud中Hystrix、Ribbon及Feign的熔断关系是什么?

    导读 今天和大家聊一聊在Spring Cloud微服务框架实践中,比较核心但是又很容易把人搞得稀里糊涂的一个问题,那就是在Spring Cloud中Hystrix.Ribbon以及Feign它们三者之 ...

  2. Spring Cloud中Hystrix 线程隔离导致ThreadLocal数据丢失问题分析

    最近spring boot项目中由于使用了spring cloud 的hystrix 导致了threadLocal中数据丢失,其实具体也没有使用hystrix,但是显示的把他打开了,导致了此问题. 导 ...

  3. Spring Cloud 之 Hystrix.

    一.概述  在微服务架构中,我们将系统拆分成了很多服务单元,各单元的应用间通过服务注册与订阅的方式互相依赖.由于每个单元都在不同的进程中运行,依赖通过远程调用的方式执行,这样就有可能因为网络原因或是依 ...

  4. 笔记:Spring Cloud Feign Hystrix 配置

    在 Spring Cloud Feign 中,除了引入了用户客户端负载均衡的 Spring Cloud Ribbon 之外,还引入了服务保护与容错的工具 Hystrix,默认情况下,Spring Cl ...

  5. 架构师系列文:通过Spring Cloud组件Hystrix合并请求

    在前文里,我们讲述了通过Hystrix进行容错处理的方式,这里我们将讲述通过Hystrix合并请求的方式 哪怕一个URL请求调用的功能再简单,Web应用服务都至少会开启一个线程来提供服务,换句话说,有 ...

  6. 从零开始学spring cloud(十一) -------- hystrix监控

    一.官方文档阅读 服务启动后,可以通过/health和hystrix.stream查看效果,实际上,访问上述两个地址,会出现404,这是因为spring boot版本的问题, 我在这里使用的sprin ...

  7. Spring Cloud断路器Hystrix

    在微服务架构中,存在着那么多的服务单元,若一个单元出现故障,就会因依赖关系形成故障蔓延,最终导致整个系统的瘫痪,这样的架构相较传统架构就更加的不稳定.为了解决这样的问题,因此产生了断路器模式. 什么是 ...

  8. Spring Cloud 关于 hystrix 的异常 fallback method wasn't found

    在 Spring Cloud 中使用断路器 hystrix 后,可能会遇到异常:com.netflix.hystrix.contrib.javanica.exception.FallbackDefin ...

  9. Spring Cloud之Hystrix服务保护框架

    服务保护利器 微服务高可用技术 大型复杂的分布式系统中,高可用相关的技术架构非常重要. 高可用架构非常重要的一个环节,就是如何将分布式系统中的各个服务打造成高可用的服务,从而足以应对分布式系统环境中的 ...

随机推荐

  1. 最短路径--Floyd算法

    Floyd算法 1.定义概览 Floyd-Warshall算法(Floyd-Warshall algorithm)是解决任意两点间的最短路径的一种算法,可以正确处理有向图或负权的最短路径问题,同时也被 ...

  2. N天学习一个linux命令之du

    用途 统计文件或者目录占用硬盘空间大小 用法 du [OPTION] [FILE]du [OPTION] --files0-from=F 常用参数 -a, --all统计所有文件,不仅仅是目录 -b, ...

  3. [React Storybook] Get started with Storybook for React

    Storybook is a UI component development environment for React, Vue, and Angular. With that, you can ...

  4. C语言之文件操作07——读取文件数据并计算均值方差标准差

    //文件 /* =============================================================== 题目:从文本文件"high.txt" ...

  5. android.os.TransactionTooLargeException

    android.os.TransactionTooLargeException 今天开发过程共遇到问题,后台要反回一些表格,不是单纯的数据.就是有一些html标签的东西.错误的思路: 我得到数据后通过 ...

  6. http get请求获取server返回的应答数据

    libcurl库中的參数CURLOPT_WRITEFUNCTION所设置的回调函数应该是这种: size_t fun_cb( char *ptr, size_t size, size_t nmemb, ...

  7. LeetCode OJ 之 Valid Anagram

    题目: Given two strings s and t, write a function to determine if t is an anagram of s. For example, s ...

  8. [面试题]java中final finally finalized 的差别是什么?

    final 是修饰符,能够用于修饰变量.方法和类.修饰变量时.代表变量不能够改动,也就是常量了.常量须要在定义时赋值或通过构造函数赋值,两者仅仅能选其一:修饰方法时,代表方法仅仅能调用,不能被 ove ...

  9. STL_算法_逆转(reverse,reverse_copy)

    C++ Primer 学习中.. . 简单记录下我的学习过程 (代码为主) //全部容器适用 reverse(b,e)        //逆转区间数据 reverse_copy(b,e,b2) /** ...

  10. 【POJ 2449】 Remmarguts' Date

    [题目链接] http://poj.org/problem?id=2449 [算法] A*(启发式搜索) 首先,求第k短路可以用优先队列BFS实现,当T第k次入队时,就求得了第k短路,但是,这种做法的 ...