9. Ali Sentinel Sentinel

1.Sentinel

        Sentinel (Sentinel) is a traffic control and circuit breaker degradation framework open sourced by Ali, which is used to protect applications in distributed systems from traffic influx, overload and failure. It can be used as a part of the microservice architecture to protect the service from being overwhelmed by abnormal traffic, thereby improving the stability and reliability of the system.

1.1 Sentinel download

https://github.com/alibaba/Sentinel/releases https://github.com/alibaba/Sentinel/releases         command line start

java -Dserver.port=8858 -Dcsp.sentinel.dashboard.server=localhost:8080 -Dproject.name=sentinel-dashboard -jar sentinel-dashboard-1.8.2.jar

1.2 Use of Sentinel

        import dependencies

<dependency>
    <groupId>com.alibaba.cloud</groupId>
    <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
    <version>2.2.9.RELEASE</version>
</dependency>

        Configure the main configuration class

spring:
  application:
    name: cart
  cloud:
    sentinel:
      transport:
        dashboard: 192.168.5.224:8858

        Visit http://192.168.5.224:8858 on the web page (login account and password are sentinel by default)

1.3 Sentinel implements service degradation and current limiting

        Service degradation is a kind of temporary shutdown of some non-core functions or provision of simplified services in order to ensure the stability and availability of core functions when the system encounters abnormal conditions or high loads. Through service degradation, the system can continue to operate normally under abnormal conditions, without causing the entire system to be unavailable due to abnormal conditions.

        Add annotation SentinelResource on the method

        fallback: downgrade; addFallBack: downgrade method name; blockHandler: current limit;

@SentinelResource(fallback = "addFallBack", blockHandler = "addBlockHandler")
@GetMapping("/test")
public String test(){
    return "cart";
}
public String addFallBack(){
    return "fallback";
}
//限流方法
public String addBlockHandler(BlockException e){
    return e.getMessage();
}

        Set the current limiting method in the console, etc.

Guess you like

Origin blog.csdn.net/LB_bei/article/details/132459391