Getting Started with Alibaba Sentinel for Flow Control and Circuit Breaking in Spring Boot

This article introduces Alibaba Sentinel, explains its key features for traffic control and circuit breaking, and provides a step‑by‑step guide to set up the Sentinel dashboard, integrate the client into a Spring Boot project, configure rules, and verify flow‑control in action.

Top Architect
Top Architect
Top Architect
Getting Started with Alibaba Sentinel for Flow Control and Circuit Breaking in Spring Boot

Sentinel is an open‑source flow‑control and circuit‑breaker framework from Alibaba that provides a visual console for managing traffic, protecting service stability in microservice architectures.

Key features include rich application scenarios (e.g., flash‑sale traffic spikes, message peak‑valley smoothing), real‑time monitoring of single‑machine and cluster metrics, extensive integration with Spring Cloud, Dubbo, gRPC, and a complete set of SPI extension points for custom rule management.

Start the Sentinel dashboard : download the release JAR from the GitHub releases page and run it with java -jar sentinel-dashboard-1.6.0.jar. The dashboard will listen on port 8080 (or a custom port) and can be accessed at http://localhost:8080.

Client setup – create a Spring Boot project and add the following Maven pom.xml (excerpt):

<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>
        <relativePath/>
    </parent>
    <groupId>com.maimeng.baobanq</groupId>
    <artifactId>baobanserver</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>
    <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>
        <!-- sentinel -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
        </dependency>
        <!-- sentinel end -->
        <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>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

Configuration : add the Sentinel server address to application.yml:

spring:
  application:
    name: baobanserver
  cloud:
    sentinel:
      transport:
        dashboard: localhost:8080
      #eager: true   # uncomment to disable lazy loading

Define a simple REST controller:

@RestController
public class TestController {
    @GetMapping(value = "/hello")
    public String hello() {
        return "Hello Sentinel";
    }
}

Run the Spring Boot application, then access the dashboard. Initially the service list is empty because no request has been made. Invoke /hello once; the dashboard will register the service. Set a flow‑control rule for the /hello endpoint with a threshold of 1 request per second. Subsequent rapid calls will be blocked, demonstrating Sentinel’s rate‑limiting in action.

Note: Sentinel uses lazy loading by default; the rule takes effect only after the first request. To enable eager loading, remove the comment on the eager property in application.yml.

By following these steps you have a functional Sentinel integration that provides real‑time monitoring, circuit breaking, and flow control for a Spring Boot microservice.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

BackendSpring BootsentinelFlow Control
Top Architect
Written by

Top Architect

Top Architect focuses on sharing practical architecture knowledge, covering enterprise, system, website, large‑scale distributed, and high‑availability architectures, plus architecture adjustments using internet technologies. We welcome idea‑driven, sharing‑oriented architects to exchange and learn together.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.