SpringCloud - Spring Cloud Netflix 之 Hystrix ;turbine(十)

港控/mmm° 2023-09-28 10:43 211阅读 0赞

阅读本文前可先参考

SpringCloud - Spring Cloud根/父项目,开发准备(二)
https://blog.csdn.net/MinggeQingchun/article/details/125308948

https://blog.csdn.net/MinggeQingchun/article/details/125312594

https://blog.csdn.net/MinggeQingchun/article/details/125315839

Spring Cloud Hystrix Turbine

Hystrix Dashboard 的主要功能是可以对某一项微服务进行监控,但真实情况下,不可能只对一个微服务进行监控,我们有很多微服务,所以我们需要对很多微服务进行监控,这个时候就需要使用到turbine [ˈtɜːbaɪn] 来完成

Hystrix Dashboard 前面已经知道了,它的主要功能是可以对某一项微服务进行监控,但真实情况下,不可能只对一个微服务进行监控,我们有很多微服务,所以我们需要对很多微服务进行监控,这个时候就需要使用到turbine [ˈtɜːbaɪn] 来完成

单个hystrix服务的监控

f5b22b82e2204485845a40bed8e33e61.png

多个**hystrix服务的监控**

e0dddc8d276a491ea544c6ba0814db5e.png

1、新建一个springboot Module(springcloud-6-service-eureka-hystrix-turbine),设置父项目

2、添加 spring-cloud-starter-netflix-turbine等 依赖

  1. <dependencies>
  2. <!-- spring-cloud-starter-netflix-turbine -->
  3. <dependency>
  4. <groupId>org.springframework.cloud</groupId>
  5. <artifactId>spring-cloud-starter-netflix-turbine</artifactId>
  6. </dependency>
  7. </dependencies>
  8. <!--继承统一的父项目-->
  9. <parent>
  10. <groupId>com.company</groupId>
  11. <artifactId>springcloud-demo</artifactId>
  12. <version>1.0.0</version>
  13. <!-- <relativePath/> <!– lookup parent from repository –>-->
  14. </parent>
  15. <groupId>com.company</groupId>
  16. <artifactId>springcloud-6-service-eureka-hystrix-turbine</artifactId>
  17. <version>0.0.1-SNAPSHOT</version>
  18. <name>springcloud-6-service-eureka-hystrix-turbine</name>
  19. <description>Demo project for Spring Boot</description>
  20. <properties>
  21. <java.version>1.8</java.version>
  22. </properties>
  23. <dependencies>
  24. <!-- spring-cloud-starter-netflix-turbine -->
  25. <dependency>
  26. <groupId>org.springframework.cloud</groupId>
  27. <artifactId>spring-cloud-starter-netflix-turbine</artifactId>
  28. </dependency>
  29. </dependencies>
  30. <build>
  31. <plugins>
  32. <plugin>
  33. <groupId>org.springframework.boot</groupId>
  34. <artifactId>spring-boot-maven-plugin</artifactId>
  35. </plugin>
  36. </plugins>
  37. </build>

3、application.prperties配置文件中配置访问端口3722

  1. server.port=3722
  2. #不向注册中心注册自己
  3. eureka.client.register-with-eureka=false
  4. #注册中心的链接地址 http://localhost:8761/eureka
  5. eureka.client.service-url.defaultZone=http://eureka8761:8761/eureka,http://eureka8762:8762/eureka,http://eureka8763:8763/eureka
  6. #配置turbine
  7. turbine.app-config=springcloud-6-service-eureka-hystrix-consumer8081,springcloud-6-service-eureka-hystrix-consumer8082
  8. #需要有这个,没有的话聚合不了多个项目
  9. turbine.cluster-name-expression="default"

4、在 Spring Boot 的启动类中,添加@EnableTurbine 注解,//开启turbine对hystrix聚合汇总支持

  1. @EnableTurbine //开启turbine对hystrix聚合汇总支持
  2. @SpringBootApplication
  3. public class EurekaHystrix6TurbineApplication {
  4. public static void main(String[] args) {
  5. SpringApplication.run(EurekaHystrix6TurbineApplication.class, args);
  6. }
  7. }

5、创建两个服务消费者 springcloud-6-service-eureka-hystrix-consumer8081,springcloud-6-service-eureka-hystrix-consumer8082(复制自springcloud-6-service-eureka-hystrix-consumer)

6、启动springboot启动类,访问应用,再去查看 DashBoard 控制中心控制台服务

http://localhost:8080/springcloud/eureka/hystrix/goodHystrixList

http://localhost:8081/springcloud/eureka/hystrix/goodHystrixList

http://localhost:8080/actuator/hystrix.stream

http://localhost:8081/actuator/hystrix.stream

http://localhost:3722/turbine.stream

fe102781f98648eda7ad12892d157a89.png

发表评论

表情:
评论列表 (有 0 条评论,211人围观)

还没有评论,来说两句吧...

相关阅读