Spring Cloud Alibaba Sentinel initial

(I) Sentinel introduction

(1) with the popularity of microservices, the stability of service invocation becomes more and more important. Sentinel takes "flow" as a breakthrough and works in many fields such as flow control, fuse degradation and load protection to ensure service reliability. Popular: it is used to protect the role of microservices in microservice system. How to deal with service avalanche, service fuse and service degradation are used to replace Hystrix;

(2) characteristics

- rich application scenarios: Sentinel has undertaken the core scenarios of Alibaba's double 11 traffic promotion in recent 10 years, such as spike (i.e. burst traffic control within the range of system capacity), message peak shaving, cluster traffic control, real-time fusing of downstream unavailable applications, etc;

- complete real-time monitoring: Sentinel also provides real-time monitoring function. You can see the second level data of a single machine connected to the application in the console, and even the summary operation of clusters with a scale of less than 500;

- extensive open source Ecology: Sentinel provides out of the box integration modules with other open source frameworks / libraries, such as Spring Cloud, Dubbo and RPC. You can quickly access Sentinel by introducing corresponding dependencies and simple configuration.


(2) Sentinel download and installation

(1) download address: Sentinel version address


(2) I choose sentinel-dashboard-1.8.1.jar 


(3) move to the specified directory and execute sentinel-dashboard- by running the command of Jar package Jar

Manually specify the port to run in the background: nohup Java - dserver port=8888 -jar sentinel-dashboard-1.8.1. jar > catalina. out 2>&1 &

View log command: Tail - f Catalina out 

(4) browser address bar: http://localhost:8888 Enter the default user name and password. sentinel registration is successful



(3) Sentinel real time monitoring service

(1) create project import dependency

<!--introduce nacos client Dependency, service registration and discovery-->

<!--introduce sentinel Dependent service monitoring-->

(2) write the configuration in the configuration file

# Specify the service name [the default name is the same as the application name]
# 1)First statement nacos The address of the registered center of; two)The service discovery [Client] registers and refers to the address of the registration center;

# Expose all web endpoints [nacos client needs to communicate with other micro services and needs health check]

# sentinel dashboard 8888 Ports and for external access to the dashboard interface sentinel logs 8719 Communication port of internal service
# At this point, nacos-client The log information generated during service invocation will be passed to sentinel Display, and then carry out flow control, fuse degradation and load protection for the service

Note: after the project is started, the micro service will be automatically handed over to Sentinel traffic guard for management, but access the Dashboard interface to check the service monitoring and find that there is nothing in the interface? The

By default, Sentinel is delayed loading, and service monitoring will not be created immediately after startup. It will be initialized only when the service needs to be called;

You can also manually add the configuration when the micro service is started: spring cloud. Sentinel. Eager = true - Sentinel loads the micro service immediately instead of delaying loading.

(3) write a simple test demo

public class SentinelController {
    public String test(){
        log.info("sentinel test");
        return "sentinel test ";

    public String test1(){
        log.info("sentinel test1");
        return "sentinel test1 ";

(4) when calling the microservice, the call volume of QPS will appear





Tags: Distribution

Posted by adamhhh on Thu, 14 Apr 2022 19:42:41 +0930