I. Introduction to Hystrix Turbine
There is not much value in looking at the data of a single Hystrix Dashboard. To look at the data of this system's Hystrix Dashboard, you need to use Hystrix Turbine. Hystrix Turbine consolidates the data of each service's Hystrix Dashboard. The use of Hystrix Turbine is very simple. You only need to introduce corresponding dependency and add annotation and configuration.
II. Preparations
The project used in this paper is the project of the previous article, on this basis, the transformation is carried out. Because we need a Dashboard of multiple services, we need to create another service, named service Lucy. Its basic configuration is the same as service hi. For details, see the source code, which will not be explained in detail here.
III. create service turbine
Introduce 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 serviceturboneapplication, turn on turbine, and the @ EnableTurbine annotation contains 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 # Specify which clusters to aggregate. Multiple clusters are divided by "," and the default is default. You can use http: / /... / turbine. Stream? Cluster = {one of clusterconfig} to access appConfig: service-hi,service-la ### Configure the serviceId list in Eureka to indicate which services to monitor clusterNameExpression: new String("default") # 1. clusterNameExpression specifies the cluster name, and the default expression is appName. At this time: turbine.aggregator.clusterConfig needs to configure the application name to be monitored # 2. When clusterNameExpression: default, turbo.aggregator.clusterconfig can be left blank, because default is default # 3. When clusterNameExpression: metadata['cluster '], if the application you want to monitor is configured with Eureka. Instance. Metadata map. Cluster: ABC, you need to configure it. At the same time, turn.aggregator.clusterconfig: ABC eureka: client: serviceUrl: defaultZone: http://localhost:8761/eureka/
Turbine demo
Start the server, service Hi, service La and service turbine projects successively.
Open browser input: http://localhost:8769/turbine.stream,
Request in turn:
http://localhost:8762/hi?name=whhttp://localhost:8763/hi?name=wh
Open: http://localhost:8763/hystrix, Input monitoring flow http://localhost:8769/turbine.stream , click monitor stream, and you can see that this page aggregates the hystrix dashbord data of two service s.
java B2B2C springmvc mybatis e-commerce platform source code