“This is the 20th day of my participation in the Gwen Challenge in November. Check out the details: The Last Gwen Challenge in 2021.”

1, the introduction of

The Hystrix Dashboard, while useful, has one drawback: a Hystrix Dashboard can only collect one Hystrix stream of microservices. This means that for each microservice, we need to turn on a Hystrix Dashboard to monitor its health. Note The Hystrix Dashboard can only enter one ACTUATOR endpoint address.

It can endure? I can’t stand it anyway.

If it’s unbearable, we can use Turbine; With Turbine, Netfilx is aggregating Hystrix streams from multiple microservices into a single stream and displaying them through a Hystrix Dashboard, which makes it nice to monitor the health of multiple microservices simultaneously.

The rough structure diagram of Turbine project is as follows:

Before Turbine, each micro-service needs to open a Hystrix Dashboard page to monitor the health of the current micro-service. After Turbine, the information of multiple micro-services is aggregated through Turbine and then displayed in a Hystrix Dashboard page.

2, the body

2.1 Quick Construction

List of services:

I have set up six services in total, among which Eureka-Server is the registration center and turbine server is the service. Hystrix-dashboard-server is a hystrix-Dashboard service that you can also start in a service if needed. User-server, order-server, and message-server are hystrix protected services.

<modules>
  <module>eureka-server</module>
  <module>turbine-server</module>
  <module>hystrix-dashboard-server</module>
  <module>user-server</module>
  <module>order-server</module>
  <module>message-server</module>
</modules>
Copy the code

Service dependencies:

All dependencies and versions are listed below, and you can select the required dependencies from the specified service

<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> < version > 2.3.4. RELEASE < / version > < / parent > < properties > < spring - cloud. Version > Hoxton. RELEASE < / spring - cloud. Version > </properties> <dependencies> <! --web--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <! --actuator--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <! --eureka server--> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId> </dependency> <! --eureka client--> <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</artifactId> </dependency> <! --turbine--> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-turbine</artifactId> </dependency> <! --hystrix-dashboard--> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId> </dependency> </dependencies> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>${spring-cloud.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>Copy the code

Eureka-server service construction:

Application. Yml configuration file

server:
  port: 4010

spring:
  application:
    name: eureka-server

eureka:
  instance:
    hostname: localhost
  client:
    register-with-eureka: false
    fetch-registry: false
    service-url:
      defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka
Copy the code

Service startup class

@SpringBootApplication @EnableEurekaServer public class EurekaServerApp { public static void main(String[] args) { SpringApplication.run(EurekaServerApp.class, args); }}Copy the code

User-server, order-server, message-server

User-server service application.yml configuration file (the other two are similar)

server: port: 22222 spring: application: name: user-server eureka: client: service-url: defaultZone: http://localhost:4010/eureka # # open hystrix. Stream endpoint management: endpoints: web: exposure: the include: 'hystrix. Stream'Copy the code

User-server service startup class (the other two are similar)

@springBootApplication @enableeurekaclient // Hystrix @enableHystrix public class UserServerApp {public static void main(String[] args) { SpringApplication.run(UserServerApp.class, args); }}Copy the code

User-server writes hystrix protected controller (the other two are similar)

@RestController @RequestMapping(value = "/user") public class UserController { @GetMapping @HystrixCommand(fallbackMethod = "fallback") public String userDemo() { return "user-98"; } // The two methods are written to demonstrate that the method names are different, Hystrix dashboard creates different circuit @getMapping ("/demo1") @hystrixCommand (fallbackMethod = "fallback") public String userDemo1() { return "user-98"; } private String fallback() { return "user-NaN"; }}Copy the code

Turbine – Server service construction:

Application. Yml configuration file

server: port: 11111 spring: application: name: turbine-server eureka: client: service-url: defaultZone: http://localhost:4010/eureka turbine: # # had been in the service name list app - config: Order-server,user-server,message-server ## eureka cluster name, default cluster-name-expression: By default, turbine will aggregate services under a unified host into one service to count combine-host-port: trueCopy the code

Start turbine class, add @enableTurbine to start Turbine

@enableturbine public class TurbineServerApp {public static void main(String[]) args) { SpringApplication.run(TurbineServerApp.class, args); }}Copy the code

Hystrix-dashboard-server Service Setup:

Application. Yml configuration file

Server: port: 55555 eureka: client: service - url: defaultZone: http://localhost:4010/eureka # # don't register register - with - eureka: falseCopy the code

Start class, add @enableHystrixDashboard start HystrixDashboard

@SpringBootApplication
@EnableHystrixDashboard
public class HystrixDashboardServerApp {

    public static void main(String[] args) {
        SpringApplication.run(HystrixDashboardServerApp.class, args);
    }

}
Copy the code

2.2 Starting the Service

Service startup should start the registry Eureka-server first, then user-server, order-server, message-server services, and finally start turbine- Server and Hystrix-dashboard – Server.

After starting the eureka-Server, check whether the service is registered in the Eureka-Server registry

http://localhost:4010/

Then access the Hystrix endpoint of the Hystrix-Dashboard-Server service and ensure that the following Hystrix Dashboard interface is displayed

http://localhost:55555/hystrix

Enter the turbine. Stream endpoint provided by turbine- Server into the Hystrix dashboard

http://localhost:11111/turbine.stream

At the initial entry, no data was reported because the methods protected by Hystrix were not called, so each interface needed to be called to trigger data reporting.

If the following page is displayed, the monitoring service is successfully started and integrated

2.3 Precautions

The circuit data displayed in the Hystrix dashboard will be created based on the method name. Therefore, hystrix protected methods in the same service will be displayed together if the method name is the same.

A circuit corresponds to a pool of threads

  • The number of circuits is equal to the number of method names
  • Thread Pools creates one for each hystrix-protected method class