How to Set Up Alibaba Sentinel for Rate Limiting in a Spring Boot Microservice
This guide walks you through installing Alibaba Sentinel’s dashboard, configuring a Spring Boot client, defining flow rules, and verifying that request throttling works, providing all necessary commands, Maven snippets, YAML settings, and UI screenshots for a complete end‑to‑end rate‑limiting solution.
Introduction
Sentinel is an open‑source rate‑limiting and circuit‑breaker framework from Alibaba that includes a visual dashboard for monitoring and rule management. It is widely used in microservice architectures to protect services from overload, burst traffic, and downstream failures.
Key Features
Rich application scenarios : Handles flash‑sale spikes, message peak‑shaving, and real‑time circuit breaking.
Real‑time monitoring : Shows per‑instance and aggregated metrics in the dashboard.
Broad ecosystem : Provides out‑of‑the‑box integrations with Spring Cloud, Dubbo, gRPC, etc.
Extensible SPI : Allows custom rule management and data‑source adapters.
Running the Sentinel Dashboard (Server)
Download the latest sentinel-dashboard JAR from the GitHub releases page ( https://github.com/alibaba/Sentinel/releases) and start it: java -jar sentinel-dashboard-1.6.0.jar The dashboard runs on port 8080 by default. Open http://localhost:8080 and log in with the default username/password sentinel.
Setting Up the Spring Boot Client
Create a Spring Boot project and add the following Maven dependencies:
<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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.5.RELEASE</version>
</parent>
<groupId>com.example</groupId>
<artifactId>sentinel-demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Finchley.SR1</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>0.2.2.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project>Note: Use version 0.2.x for Spring Boot 2.x projects; older Spring Boot 1.x requires 0.1.x.
Configuration
Add the Sentinel dashboard address to application.yml:
spring:
application:
name: sentinel-demo
cloud:
sentinel:
transport:
dashboard: localhost:8080
#eager: true # Uncomment to disable lazy loadingController Example
@RestController
public class TestController {
@GetMapping("/hello")
public String hello() {
return "Hello Sentinel";
}
}Run the Spring Boot application. The dashboard will initially show no client because Sentinel loads rules lazily.
Defining a Flow Rule
After the first request to /hello, the client appears in the dashboard. Open the “Flow Control” tab for the /hello resource and set the QPS threshold to 1. This limits the endpoint to one request per second.
Verification
Send multiple rapid requests to /hello. The dashboard shows the QPS statistics and the requests exceeding the limit are blocked, confirming that rate limiting is active.
By following these steps you have a functional Sentinel setup that provides real‑time monitoring, rule management, and effective traffic throttling for your Spring Boot microservice.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Java Architect Essentials
Committed to sharing quality articles and tutorials to help Java programmers progress from junior to mid-level to senior architect. We curate high-quality learning resources, interview questions, videos, and projects from across the internet to help you systematically improve your Java architecture skills. Follow and reply '1024' to get Java programming resources. Learn together, grow together.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
