This article has participated in the activity of "New person creation Ceremony", and started the road of digging gold creation together.

1, Hystrix

1.1. Problems faced by distributed systems

  • Applications in complex distributed architectures have dozens of dependencies, each of which will inevitably fail at some point.

  • If one of these microservices fails, then a service avalanche can occur.

1. Serve avalanche

  • When invoking between multiple microservices, assume microservicesAInvoking microservicesBAnd the micro serviceC, the serviceBAnd the micro serviceCAnd call other microservices, that’s what’s calledThe fan out. If the response time of a microservice invocation on the fan out link is too long or the microservice invocation is unavailable, the microservice is disabledAThe call will occupy more and more resources of the system, and then cause the system crash, the so-calledAvalanche effect.
  • Usually when you find that an instance of a module fails, the module still receives traffic, and then the module in question calls other modules, cascading failures, or avalanches, occur.

1.2 overview of Hystrix

  • HystrixIs a system for dealing with distributed systemsdelayandFault toleranceIn distributed systems, many dependencies inevitably fail to be called, such as timeouts, exceptions, etc.HystrixTo ensure that in the event of a dependency failure,This prevents overall microservice failures and avoids cascading failures to improve the resiliency of distributed systems.
  • The circuit breaker itself is a kind of switching device. When a service unit fails, the fault monitoring of the circuit breaker (similar to blowing a fuse) returns an expected and manageable alternative response to the caller, rather than waiting for a long time or throwing exceptions that cannot be handled by the calling method. This ensures that the threads of the service callers are not tied up unnecessarily for long periods of time, thus preventing failures from spreading and even avalanches in a distributed system.

1.3 purposes of Hystrix

The website address

  1. Service degradation
  2. Service fusing
  3. Near real-time monitoring

We are in a standstill, but we need to learn the same ideas.

1.4. Important concepts of Hystrix

1. The service is degraded

  • The server is busy, please try again later, do not let the client wait and immediately return a friendly message,fallbackThere will be a bottom-of-the-line solution.

A situation that triggers a downgrade

  1. Abnormal program running
  2. timeout
  3. Service fuse fault triggers service degradation
  4. A full thread pool/semaphore can also cause service degradation

2. Service fuse

  • When the fuse reaches the maximum service access, the access is directly denied, the power is cut off, and then the method of service degradation is called and a friendly prompt is returned.
  • Degradation of the service -> further fuses -> recovery of the calling link

3. Traffic limiting

  • Second kill high concurrent operation, it is strictly prohibited to rush over crowded, we queue up, one secondNIn order.

1.5. Case environment construction

1.5.1 Payment module

1. To build the Module

  • ModuleFor the name of thecloud-provider-hystrix-payment8001.

2. Change the POM


      
<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">
    <parent>
        <artifactId>cloud02</artifactId>
        <groupId>com.xiao</groupId>
        <version>1.0 the SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>


    <artifactId>cloud-provider-hystrix-payment8001</artifactId>


    <dependencies>
        <! - new hystrix -- -- >
        <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-eureka-client</artifactId>
        </dependency>


        <dependency>
            <groupId>com.xiao</groupId>
            <artifactId>cloud-api-commons</artifactId>
            <version>1.0 the SNAPSHOT</version>
        </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.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

</project>

Copy the code

3. Change to YML

server:
  port: 8001


eureka:
  client:
    register-with-eureka: true    Do not register yourself with the registry
    fetch-registry: true   # represents a registry that maintains service instances and does not need to retrieve services
    service-url:
      # defaultZone: http://eureka7002.com:7002/eureka/ # set and had the address of the server to interact query service and registration services need to rely on this address
      defaultZone: http://eureka7001.com:7001/eureka/
# server:
# enable-self-preservation: false
spring:
  application:
    name: cloud-provider-hystrix-payment
  # eviction-interval-timer-in-ms: 2000

Copy the code

4. The main launch

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;

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

5. PaymentService class

import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

@Service
public class PaymentService {

    public String paymentInfo_OK(Integer id){
        return "Thread pool:"+Thread.currentThread().getName()+"PaymentInfo_OK, id:"+id+"\t"+"Ha ha ha."  ;
    }

    / / fail
    public String paymentInfo_TimeOut(Integer id){
        int timeNumber = 3;
        try { TimeUnit.SECONDS.sleep(timeNumber); }catch(Exception e) {e.printStackTrace(); }return "Thread pool:"+Thread.currentThread().getName()+"PaymentInfo_TimeOut, id:"+id+"\t"+"Woo woo woo"+"Time (seconds)"+timeNumber; }}Copy the code

6. PaymentController class

import com.xiao.cloud.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@Slf4j
public class PaymentController {

    @Resource
    private PaymentService paymentService;

    @Value("${server.port}")
    private String serverPort;

    @GetMapping("/payment/hystrix/ok/{id}")
    public String paymentInfo_OK(@PathVariable("id") Integer id){
        String result = paymentService.paymentInfo_OK(id);
        log.info("*******result:"+result);
        return result;
    }
    @GetMapping("/payment/hystrix/timeout/{id}")
    public String paymentInfo_TimeOut(@PathVariable("id") Integer id){
        String result = paymentService.paymentInfo_TimeOut(id);
        log.info("*******result:"+result);
        returnresult; }}Copy the code

7. Test results

(1) Check the registry


(2) URL access view


8. High concurrency stress test

  • The pair will pause when we use the high concurrency test tool3Of a secondURLsend20000When you make a request, you’ll find twoURLAll requests take time to respond.

(1) The reasons for this

  • Because a large number of requests are made to access the correspondingURLhttp://localhost:8001/payment/hystrix/timeout/1, thentomcatMost of the threads handle the large number of URL requestshttp://localhost:8001/payment/hystrix/timeout/1So if we ask againhttp://localhost:8001/payment/hystrix/ok/1, then you need to wait a certain amount of time.

1.5.2 Order module

1. To build the Module

  • ModuleFor the name of thecloud-consumer-feign-hystrix-order80.

2. Change the POM

    <dependencies>
        <! - new hystrix -- -- >
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-openfeign</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>
        <dependency>
            <groupId>com.xiao</groupId>
            <artifactId>cloud-api-commons</artifactId>
            <version>1.0 the SNAPSHOT</version>
        </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.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

Copy the code

3. Change to YML

server:
  port: 80


eureka:
  client:
    register-with-eureka: false    Do not register yourself with the registry
    service-url:
      defaultZone: http://eureka7001.com:7001/eureka/
Copy the code

4. The main launch

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;

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

5. PaymentHystrixService class

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

@Component
@FeignClient(value = "CLOUD-PROVIDER-HYSTRIX-PAYMENT")
public interface PaymentHystrixService {

    @GetMapping("/payment/hystrix/ok/{id}")
    public String paymentInfo_OK(@PathVariable("id") Integer id);

    @GetMapping("/payment/hystrix/timeout/{id}")
    public String paymentInfo_TimeOut(@PathVariable("id") Integer id);
}

Copy the code

6. OrderHystrixController class

import com.xiao.cloud.service.PaymentHystrixService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class OrderHystrixController {

    @Autowired
    private PaymentHystrixService paymentHystrixService;


    @GetMapping("/consumer/payment/hystrix/ok/{id}")
    public String paymentInfo_OK(@PathVariable("id") Integer id){
        String result = paymentHystrixService.paymentInfo_OK(id);
        return result;
    }

    @GetMapping("/consumer/payment/hystrix/timeout/{id}")
    public String paymentInfo_TimeOut(@PathVariable("id") Integer id){
        String result = paymentHystrixService.paymentInfo_TimeOut(id);
        returnresult; }}Copy the code

7. High concurrency test results

1.6. Solutions and requirements

1. Address the request

  1. Timeout causes the server to slow (spin), that is, timeout does not wait.
  2. An error (downtime or program execution error), that is, there is a reason for the error.

2. Solutions

  1. Counterparty service (8001) timed out, caller (80) There must be a service downgrade.
  2. Counterparty service (8001)downThe caller (80) There must be a service downgrade.
  3. Counterparty service (8001)OK, the caller (80) they fail or have self-requirements (their own wait time is less than the service provider’s) and handle the degradation themselves

1.7. Service degradation

1.7.1 Service degradation on the payment side

1. Modify PaymentService

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

@Service
public class PaymentService {

    public String paymentInfo_OK(Integer id){
        return "Thread pool:"+Thread.currentThread().getName()+"PaymentInfo_OK, id:"+id+"\t"+"Ha ha ha."  ;
    }

    / / fail
    @HystrixCommand(fallbackMethod = "paymentInfo_TimeOutHandler" ,commandProperties = { @HystrixProperty(name = "Execution. The isolation. Thread. TimeoutInMilliseconds," value = "3000") / /} is normal business logic within 3 seconds)
    public String paymentInfo_TimeOut(Integer id){
        int timeNumber = 5;
        try { TimeUnit.SECONDS.sleep(timeNumber); }catch(Exception e) {e.printStackTrace(); }return "Thread pool:"+Thread.currentThread().getName()+"PaymentInfo_TimeOut, id:"+id+"\t"+"Woo woo woo"+"Time (seconds)"+timeNumber;
    }

    public String paymentInfo_TimeOutHandler(Integer id){
        return "Thread pool:"+Thread.currentThread().getName()+"System timeout or service busy, please try again later paymentInfo_TimeOutHandler,id:"+id+"\t"+"/ (ㄒ o ㄒ) / ~ ~"; }}Copy the code

2. Add the following annotations to the main startup class

  • @EnableCircuitBreakerEnable the corresponding global configuration.

3. Test results

  • Here we simulate that when our corresponding thread times out or an exception occurs, we execute our configured bottom-pocket method, which is service degradation.

1.7.2 The order-side service is degraded

1. Add the following code to the YML file

feign:
  hystrix:
    enabled: true # turn on if you handle your own fault tolerance. The enabling mode is different from that at the production end.

Copy the code

2. Add the following annotations to the main startup class

  • @EnableHystrix.

3. Add the following code to the OrderHystrixController class

@GetMapping("/consumer/payment/hystrix/timeout/{id}")
@HystrixCommand(fallbackMethod = "paymentTimeOutFallbackMethod",commandProperties = { @HystrixProperty(name = "Execution. The isolation. Thread. TimeoutInMilliseconds," value = "1500") / /} is normal business logic within 3 seconds)
public String paymentInfo_TimeOut(@PathVariable("id") Integer id){
    String result = paymentHystrixService.paymentInfo_TimeOut(id);
    return result;
}

// The bottom line
public String paymentTimeOutFallbackMethod(@PathVariable("id") Integer id){
    return "I am consumer 80, the payment system is busy, please try again 10 seconds later or check yourself,(┬ _ ┬)";
}
 

Copy the code

4. Test results

  • In the consumer 80 side we set the service degrade, when the service times out, we implement our bottom line method.

1.7.3 Current problems and solutions

1. Current problems

  1. Each business method corresponds to a bottom-of-the-envelope method, code bloat
  2. Bottom-of-the-line approaches are mixed with business logic

2. Solutions

(1) Solve the problem of code inflation

1. TheOrderHystrixControllerThe code for the class is changed to the following

import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import com.xiao.cloud.service.PaymentHystrixService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
@DefaultProperties(defaultFallback = "payment_Global_FallbackMethod")
public class OrderHystrixController {

    @Autowired
    private PaymentHystrixService paymentHystrixService;


    @GetMapping("/consumer/payment/hystrix/ok/{id}")
    public String paymentInfo_OK(@PathVariable("id") Integer id){
        String result = paymentHystrixService.paymentInfo_OK(id);
        return result;
    }

    @GetMapping("/consumer/payment/hystrix/timeout/{id}")
// @HystrixCommand(fallbackMethod = "paymentTimeOutFallbackMethod",commandProperties = {
/ / @ HystrixProperty (name = "execution. The isolation. Thread. TimeoutInMilliseconds", value = "1500") / / is normal business logic within 3 seconds
/ /})
    @HystrixCommand
    public String paymentInfo_TimeOut(@PathVariable("id") Integer id){
        int age = 10 / 0;
        String result = paymentHystrixService.paymentInfo_TimeOut(id);
        return result;
    }

    // The bottom line
    public String paymentTimeOutFallbackMethod(@PathVariable("id") Integer id){
        return "I am consumer 80, the payment system is busy, please try again 10 seconds later or check yourself,(┬ _ ┬)";
    }

    // Global bottom-saving method
    public String payment_Global_FallbackMethod(a){
        return "Global exception handling message, please try again later,(┬ _ ┬)"; }}Copy the code

2. Test results

  • Here we set up a global bottom-pocket method, which we configure on the class, so that most of the methods in the classfallbackThat’s the bottom line. And it needs to be noted above the use of the bottom pocket method@HystrixCommandAnnotation.
  • If we need to customize the methods in particularfallback, then we need to carry out relevant detailed configuration,Refer to the previous payment side and order side configuration.

(2) Solve the problem of code confusion

1. Create one in the order modulePaymentFallbackServiceClass implementsPaymentFeignClientServiceinterface

import org.springframework.stereotype.Component;

@Component
public class PaymentFallbackService implements PaymentHystrixService{
    @Override
    public String paymentInfo_OK(Integer id) {
        return "-----PaymentFallbackService fall back-paymentInfo_OK, (┬ _ ┬)";
    }

    @Override
    public String paymentInfo_TimeOut(Integer id) {
        return "-----PaymentFallbackService fall back-paymentInfo_timeout, (┬ _ ┬)"; }}Copy the code

In 2.ymlAdd the following code to the file

feign:
  hystrix:
    enabled: true # turn on if you handle your own fault tolerance. The enabling mode is different from that at the production end.
Copy the code

3. Add the following annotations to the corresponding microservice invocation interface

@FeignClient(value = "CLOUD-PROVIDER-HYSTRIX-PAYMENT",fallback = PaymentFallbackService.class)
Copy the code

4. Test results

  • Here, we put down the payment module of 8001 in advance to simulate the outage of the payment microservice module. It can be found that when the payment microservice module goes down, the microservice invocation interface will use its configured Fallback and implement the method in the implementation class of the interface.

1.8 service fuse

1.8.1 Overview of circuit breaker mechanism

  • Circuit breaker mechanism is a micro – service protection mechanism against avalanche effect. If a microservice on the fan out link is unavailable or the response time is too long, the service is degraded. In this way, the microservice invocation of the node is interrupted and an incorrect response message is quickly returned. When detecting that the microservice invocation response of this node is normal, the call link is restored.
  • inSpringCloudIn the frame, the circuit breaker mechanism passesHystrixThe implementation.HystrixThe status of calls between microservices is monitored and a circuit breaker is activated when a certain threshold of failed calls is reached. The notes of circuit breaker mechanism@HystrixCommand.

1.8.2 Fusing configuration procedure

1. Modify the PaymentService class of Cloud-provider-Hystrix-Payment8001

    // Service fuse
    @HystrixCommand(fallbackMethod = "paymentCircuitBreaker_fallback",commandProperties = { @HystrixProperty(name = "circuitBreaker.enabled",value = "true"), / / whether open circuit breaker @ HystrixProperty (name = "circuitBreaker. RequestVolumeThreshold", value = "10"), / / request times @ HystrixProperty (name = "circuitBreaker. SleepWindowInMilliseconds", value = "10000"), / / time range @ HystrixProperty (name = "circuitBreaker. ErrorThresholdPercentage", value = "60"), / / what is the failure rate after tripping})
    public String paymentCircuitBreaker(@PathVariable("id") Integer id){
        if (id < 0) {throw new RuntimeException("***** ID cannot be negative");
        }
        String serialNumber = IdUtil.simpleUUID();

        return Thread.currentThread().getName()+"\t"+"Call successful, serial number:"+serialNumber;
    }
    public String paymentCircuitBreaker_fallback(@PathVariable("id") Integer id){
        return "Id cannot be negative, please try again later,(┬ _ ┬)/~~ id: +id;
    }
Copy the code
  • Parameter Description: The requestVolumeThreshold is set to 10, indicating that a service is eligible for a service meltdown only after the number of requests exceeds 10. The errorThresholdPercentage is 60, indicating that a service meltdown occurs when the probability of an error exceeds 60%. If the error probability is lower than 60%, the call link will be recovered slowly. SleepWindowInMilliseconds 10000 said when fusing phenomenon after 10 seconds will call link to recover.

2. Modify the PaymentController class of Cloud-provider-Hystrix-Payment8001

    //=== Service fuse
    @GetMapping("/payment/circuit/{id}")
    public String paymentCircuitBreaker(@PathVariable("id") Integer id){
        String result = paymentService.paymentCircuitBreaker(id);
        log.info("*******result:"+result);
        return result;
    }
Copy the code

3. Test results

  • When we enter a positive id, it returns a negative id, so a service fusing has occurred.

1.8.3 summary

1. Three status descriptions

  • Fuse open: Instead of invoking the current service, the request callsfallback, the internal clock is generally set asMTTR(average troubleshooting time), when the opening time reaches the set clock, it enters the fusing state
  • Fuse closure: The fuse closure does not fuse the service
  • Fuse half open: This state occurs after the hibernation time window for entering the fuse open state expires. Some requests invoke the current service according to the rules. If the request is successful and meets the rules, the current service is considered normal and the circuit breaker is disabled

2. Description of important parameters

  1. requestVolumeThreshold: The circuit breaker is turned on when a certain threshold is met (default)10Seconds more than20Number of requests)
  2. errorThresholdPercentage: The circuit breaker opens when the failure rate reaches a certain level (default)10Seconds more than50%Request failed)
  3. sleepWindowInMilliseconds: After a period of time (default is5Seconds), the breaker is half-open and will allow one of the requests to be forwarded. If successful, the circuit breaker will close, if not, continue to open.

1.9. Hystrix Workflow

The working process

1. Each request is encapsulated in HystrixCommand 2. The request will be invoked synchronously or asynchronously 3. Check whether the fuse is turned on. If so, it will jump to 8 and degrade 4. Check whether the thread pool/queue/semaphore is full. If so, go to step 8 5. If there are no previous errors, we call the run method and run the dependent logic 5. Running the method may time out, and after the timeout from 5A to 8, we degrade 6. 6. If the operation is normal, it will enter 6A and return to 6a as normal. Calculate Circuit Health, the brain of Hystrix, calculates whether to fuse based on errors and successful calls. Degradation method (8A did not achieve degradation, 8B achieved degradation and successful operation, 8C achieved degradation method, but abnormal) 8A. If the degraded method is not implemented, the abnormal information is directly returned to 8B. If the degraded method is implemented and the degraded method runs successfully, the default information after the degraded is returned to 8C. Implement the degrade method, but the degrade may also appear exceptions, then return the exception information back

1.10. Hystrix Graphical DashBoard

In addition to isolating calls to dependent services, Hystrix also provides quasi-real-time call monitoring. Hystrix continuously records the execution information of all Hystrix requests and presents it to users in the form of statistical reports and graphs, including how many requests are executed per second, how many are successful, and how many are failed. Netflix monitors these metrics through the Hystrix-metrics-event-stream project. SpringCloud also provides integration with the Hystrix DashBoard, which converts monitored content into a visual interface

1.10.1. Construction process

1. To build the Module

  • ModuleFor the name of thecloud-consumer-hystrix-dashboard9001.

2. Change the POM

    <dependencies>
        <! -- Added Hystrix Dashboard -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
Copy the code

3. Change to YML

server:
  port: 9001
Copy the code

4. The main launch

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;

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

5. Test results

1.10.2 monitoring actual combat demonstration

1. Dependencies that the monitored party needs to introduce

        <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>
Copy the code

2. The code to be added on the main startup class of the monitored party

 
@Bean
public ServletRegistrationBean getServlet(a){
    HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet();
    ServletRegistrationBean registrationBean = new ServletRegistrationBean(streamServlet);
    registrationBean.setLoadOnStartup(1);
    registrationBean.addUrlMappings("/hystrix.stream");
    registrationBean.setName("HystrixMetricsStreamServlet");
    return registrationBean;
}
 

Copy the code

3. How to configure 9001 to monitor 8001

4. Test results

  • When multiple clicks sendhttp://localhost:8001/payment/circuit/-11At the time of request, the monitoring image is shown below.

5. View the rule description

(1) Figure 1


(2) Figure 2