15. Feign Integrated Circuit Breaker Monitoring Hystrix Dashboard

Posted by hrdyzlita on Sat, 07 Sep 2019 06:05:16 +0200

Public number: java paradise

Ribbon can integrate circuit breaker monitoring Hystrix Dashboard, Feign can not be less, this article explains how Feign integrated circuit breaker monitoring Hystrix Dashboard. This paper mainly integrates sc-eureka-client-consumer-feign-hystrix project and sc-hystrix-dashboard project.

1. New project sc-feign-hystrix-dashboard, the corresponding pom.xml file is as follows

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>spring-cloud</groupId>
  <artifactId>sc-feign-hystrix-dashboard</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>sc-feign-hystrix-dashboard</name>
  <url>http://maven.apache.org</url>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.4.RELEASE</version>
    </parent>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Finchley.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

        </dependencies>
    </dependencyManagement>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

    <dependencies>
    
        <!-- The explanation is one eureka client -->
        <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.cloud</groupId> 
                <artifactId>spring-cloud-starter-feign</artifactId> 
                <version>1.4.5.RELEASE</version> 
           </dependency> -->

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-openfeign</artifactId>
        </dependency>
        
        
        <!-- <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
            <version>1.4.5.RELEASE</version>
        </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-hystrix</artifactId>
            <version>1.4.5.RELEASE</version>
        </dependency> -->
        
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
        </dependency>
        
        
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
        
    </dependencies>
</project>

Note: It can be seen that this pom.xml file is a combination of the sc-eureka-client-consumer-feign-hystrix project and the sc-hystrix-dashboard project.

2. New spring root startup class FeignDashboard Application. Java

package sc.consumer;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
import org.springframework.cloud.openfeign.EnableFeignClients;

@SpringBootApplication
@EnableEurekaClient
@EnableFeignClients
@EnableHystrixDashboard
public class FeignDashboardApplication {
    
    public static void main(String[] args) {
        SpringApplication.run(FeignDashboardApplication.class, args);
    }

}

The annotation for this startup class is a union of the sc-eureka-client-consumer-feign-hystrix project and the sc-hystrix-dashboard project.
3. Other project documents are described as follows. See source code for details.

4. Start the registry sc-eureka-server and the service provider sc-eureka-client-provider, and ensure successful startup

5. Start the sc-feign-hystrix-dashboard project and verify that it started successfully
Way 1: Visit the registry to see if the service name of the sc-feign-hystrix-dashboard project configuration has been registered successfully

Mode 2: Access the address of Dashboard pair http://127.0.0.1:5800/hystrix

6. Use Hystrix Dashboard to view services
Enter at the following Icon http://127.0.0.1:5800/hystrix.stream


Then click the Monitor Stream button

7. Use postman to access any service interface. Take access access to user information interface as an example
http://127.0.0.1:5800/feign/user/getUser/3

Visit as many times as possible, then check the dashboard Bashboard monitoring background, and find that the interface that has been in Loading has changed. As shown below, the specific meaning of the unit in the diagram can be accessed to the website.
https://github.com/Netflix-Sk...

Visit http://127.0.0.1 5800/hystrix.stream also has a large amount of data, which is the monitoring data for services.

Topics: Java Spring Maven Apache