What is the Sentinel

The official title of Sentinel is: Traffic Defense for Distributed Systems. From the name, it is easy to guess that it is used for service stability. For those familiar with Spring Cloud, Hystrix should be the first response to a service stability assurance component. Unfortunately, Netflix has announced that it will not update Hystrix. So what better options do we have in the future? In addition to the resilience4J officially recommended by Spring Cloud, Sentinel integrated under Spring Cloud Alibaba is also a target for users to focus on inspection and selection.

Sentinel has so many functions and details that it is difficult to introduce it completely in one article. So I’m going to cover the key features of Sentinel in a series of articles. In this article, we’ll start with how to integrate Sentinel into Spring Cloud applications and how to use Sentinel Dashboard to configure traffic limiting rules. With this simple example, let’s set up the basic configuration.

1. Start Sentinel Dashboard

Download address:sentinel

Port =8888 -jar sentinel-dashboard-1.6.0.jar

Can pass – Dserver. Port = 8888 to start switch port, – Dserver. Servlet.. The session timeout = 7200: This parameter specifies the expiration time of the Spring Boot server session. For example, 7200 indicates 7200 seconds. 60m indicates 60 minutes. The default value is 30 minutes.

I ran into a problem with using the latest Sentinel Dashboard 1.7.1.jar

Error: Failed: Invalid type is displayed when a traffic control rule is added on the Sentinel Dashboard page

The main problem is that the jar package version of Sentinel Dashboard is too high. As a result, the Sentinel-Code version in the code is inconsistent with the Dashboard version, resulting in an error.

Issue on Github: github.com/alibaba/Sen…

After startup, enter the account password, all sentinel, to enter the main page

At this point the sentinel Dashboard startup is complete, and the project starts

To join in pom

<dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId> < version > 2.1.1. RELEASE < / version > < / dependency >Copy the code

Add related configurations to the configuration file

spring 
  cloud:
    sentinel:
      transport:
        dashboard: localhost:8080Copy the code

Write a simple interface in your project

 @GetMapping("/unLock")
 public String lock() throws Exception {
     return "success";
 }Copy the code

Just start the project and call the interface a few times before you view it on Dashboard, otherwise you may not see it on Dashboard. Here I made 500 requests using JMeter

Next, to test the function of traffic limiting, click cluster link, select the interface to limit traffic, and click Flow Control

Make 500 requests using JMeter

Current limiting effect