Spring Cloud【Finchley】-11Feign项目整合Hystrix监控

简介: Spring Cloud【Finchley】-11Feign项目整合Hystrix监控

20190806093230928.jpg

概述


我们前面的文章 Spring Cloud【Finchley】-09Feign使用Hystrix 中介绍了,如何在使用Feign的项目中使用Hystrix, 现在来探讨下如何在使用Feign的项目中监控Hystrix.


整合步骤


我们知道Hystrix的hystrix-metrics-event-stream模块 将监控信息以text/event-stream的格式暴露给外部系统。


根据spring cloud的套路来讲,一般都是 添加starter依赖,增加注解,使用


我们在原有工程中的依赖也没有找到hystrix-metrics-event-stream该依赖


20181227004405462.png


所以步骤一就是添加starter依赖

Step1.添加 spring-cloud-starter-netflix-hystrix

<dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
    </dependency>


Step2. 启动类增加@EnableCircuitBreaker或者@EnableHystrix注解


20181227004755546.png


Step3. 引入spring-boot-starter-actuator并开启端点


spring-boot-starter-actuator是必不可少的

application.yml中开启端点


#actuator  启用所有的监控端点 “*”号代表启用所有的监控端点,可以单独启用,例如,health,info,metrics
#  spring boot 升为 2.0 后,为了安全,默认 Actuator 只暴露了2个端点,heath 和 info,继续
# 访问  http://192.168.1.103:7901/actuator/metrics
management:
  endpoints:
    web:
      exposure:
        include: "*" 
  endpoint:
      health:
        show-details: ALWAYS

20181227004919872.png


Step4. 测试

  1. 启动microservice-discovery-eureka,注册中心
  2. 启动micorservice-provider-user,服务提供者
  3. 启动micorservice-consumer-movie-feign-hystrix
  4. 访问 http://localhost:7901/actuator/hystrix.stream ,如下



20181227005208216.png


  1. 访问下 http://localhost:7901/movie/3 触发hystrix收集信息
  2. 重新观察 http://localhost:7901/actuator/hystrix.stream


20181227005427906.png


代码


https://github.com/yangshangwei/SpringCloudMaster/tree/master/micorservice-consumer-movie-fegin-hystrix

相关文章
|
负载均衡 前端开发 Java
SpringCloud调用组件Feign
本文深入探讨微服务Spring体系中的Feign组件。Feign是一个声明式Web服务客户端,支持注解、编码器/解码器,与Spring MVC注解兼容,并集成Eureka、负载均衡等功能。文章详细介绍了SpringCloud整合Feign的步骤,包括依赖引入、客户端启用、接口创建及调用示例。同时,还涵盖了Feign的核心配置,如超时设置、拦截器实现(Basic认证与自定义)和日志级别调整。最后,总结了`@FeignClient`常用属性,帮助开发者更好地理解和使用Feign进行微服务间通信。
1075 1
|
消息中间件 监控 Java
如何将Spring Boot + RabbitMQ应用程序部署到Pivotal Cloud Foundry (PCF)
如何将Spring Boot + RabbitMQ应用程序部署到Pivotal Cloud Foundry (PCF)
432 6
|
Java 关系型数据库 MySQL
如何将Spring Boot + MySQL应用程序部署到Pivotal Cloud Foundry (PCF)
如何将Spring Boot + MySQL应用程序部署到Pivotal Cloud Foundry (PCF)
356 5
|
缓存 监控 Java
如何将Spring Boot应用程序部署到Pivotal Cloud Foundry (PCF)
如何将Spring Boot应用程序部署到Pivotal Cloud Foundry (PCF)
382 5
|
JSON Java 数据格式
【微服务】SpringCloud之Feign远程调用
本文介绍了使用Feign作为HTTP客户端替代RestTemplate进行远程调用的优势及具体使用方法。Feign通过声明式接口简化了HTTP请求的发送,提高了代码的可读性和维护性。文章详细描述了Feign的搭建步骤,包括引入依赖、添加注解、编写FeignClient接口和调用代码,并提供了自定义配置的示例,如修改日志级别等。
1114 1
|
前端开发 API 微服务
SpringCloud微服务之间使用Feign调用不通情况举例
SpringCloud微服务之间使用Feign调用不通情况举例
2588 2
|
Java API 开发者
【已解决】Spring Cloud Feign 上传文件,提示:the request was rejected because no multipart boundary was found的问题
【已解决】Spring Cloud Feign 上传文件,提示:the request was rejected because no multipart boundary was found的问题
2100 0
|
SpringCloudAlibaba API 开发者
新版-SpringCloud+SpringCloud Alibaba
新版-SpringCloud+SpringCloud Alibaba
|
负载均衡 Dubbo Java
Spring Cloud Alibaba与Spring Cloud区别和联系?
Spring Cloud Alibaba与Spring Cloud区别和联系?
|
Java Nacos Sentinel
Spring Cloud Alibaba:一站式微服务解决方案
Spring Cloud Alibaba(简称SCA) 是一个基于 Spring Cloud 构建的开源微服务框架,专为解决分布式系统中的服务治理、配置管理、服务发现、消息总线等问题而设计。
3249 13
Spring Cloud Alibaba:一站式微服务解决方案