SpringCloud's circuit breaker aggregation monitoring (Hystrix Turbine)

SpringCloud's circuit breaker aggregation monitoring (Hystrix Turbine)

1. Introduction
to Hystrix Turbine Looking at the data of a single Hystrix Dashboard does not have much value. If you want to see the Hystrix Dashboard data of this system, you need to use Hystrix Turbine. Hystrix Turbine integrates Hystrix Dashboard data for each service. The use of Hystrix Turbine is very simple, you only need to introduce the corresponding dependencies and add annotations and configurations.

2. Preparatory work
The project used in this article is the project of the previous article, which is to be modified on this basis. Because we need Dashboards for multiple services, we need to build another service, named service-lucy, and its basic configuration is the same as service-hi. See the source code for details, so I won t elaborate on it here.

3. create service-turbine to
introduce the corresponding dependencies:

<dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-turbine</artifactId>
        </dependency>
 
    </dependencies>
 

Add the annotation @EnableTurbine to its entry class ServiceTurbineApplication to turn on the turbine. The @EnableTurbine annotation includes the @EnableDiscoveryClient annotation, that is, the registration service is turned on.

@SpringBootApplication
@EnableEurekaClient
@EnableDiscoveryClient
@RestController
@EnableHystrix
@EnableHystrixDashboard
@EnableCircuitBreaker
@EnableTurbine
public class ServiceTurbineApplication {
 
   /**
     * http://localhost:8764/turbine.stream
     */
 
    public static void main(String[] args) {
        SpringApplication.run( ServiceTurbineApplication.class, args );
    }
}
 

Configuration file application.yml:

spring:
  application.name: service-turbine
server:
  port: 8769
security.basic.enabled: false
turbine:
  aggregator:
    clusterConfig: default   #  "," default http://.../turbine.stream?cluster={clusterConfig } 
  appConfig: service-hi,service-la  ###  Eureka serviceId 
  clusterNameExpression: new String("default")
  # 1. clusterNameExpression appName turbine.aggregator.clusterConfig 
  # 2.  clusterNameExpression: default turbine.aggregator.clusterConfig default
  # 3.  clusterNameExpression: metadata['cluster'] eureka.instance.metadata-map.cluster: ABC turbine.aggregator.clusterConfig: ABC
eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/
 

The configuration file comments are clearly written. Welcome everyone to study and research related technologies. Friends who are willing to understand the source code directly ask for exchanges and share technologies: 2147775633

The Turbine demonstration
starts the server, service-hi, service-la, and service-turbine projects in sequence.
Open the browser and enter: http://localhost:8769/turbine.stream ,

Request in turn:

http://localhost:8762/hi?name=wh
http://localhost:8763/hi?name=wh
 

Open: http://localhost:8763/hystrix, enter the monitoring stream http://localhost:8769/turbine.stream

You can see that this page aggregates the hystrix dashbord data of 2 services.