Sentinel Getting Started And Integration of Spring Cloud Alibaba Tutorials

  • 时间:
  • 浏览:3

原文链接:Sentinel Getting Started And Integration of Spring Cloud Alibaba Tutorials


This article based on:a

  • Spring Boot 2.1.5
  • Spring Cloud Greenwich.SR1
  • Spring Cloud Alibaba 0.9.0
  • Nacos 1.0.0

With the popularity of microservices, the stability between services and services is becoming more and more important. Sentinel uses traffic as an entry point to protect the stability of services from multiple dimensions such as flow control, blowdown, and system load-balance protection.

In a nutshell, Sentinel is a lightweight flow control, blowdown and degraded Java library.

Sentinel has the following characteristics:

  • Rich application scenarios:Sentinel undertakes the core scene of Alibaba's "Double Eleven" promotion traffic for nearly 10 years. For example, spikes (that is, burst flow control can be tolerated in the system capacity), message peaking and valley filling, cluster flow control, real-time fuse downstream applications that are not available.
  • Complete real-time monitoring:Sentinel also provides real-time monitoring. You can see the single machine second-level data of the access application in the console, or even the aggregate operation of clusters of less than 2000 sizes.
  • Extensive open source ecology:Sentinel Provides out-of-the-box integration modules with other open source frameworks/libraries. For example, integration with Spring Cloud, Dubbo, gRPC. You only need to introduce the appropriate dependencies and perform a simple configuration to quickly access Sentinel.
  • Complete SPI extension point:Sentinel provides an easy-to-use, comprehensive SPI expansion interface。You can quickly customize the logic by implementing an extension interface. Such as custom rule management, adapting dynamic data sources, etc.
  • Add dependencies:

  • Add configurations:

      port: 20010
        # Specify the name of the service registered to the nacos server
        name: microservice-consumer-movie
            include: '*'
  • Add Controller:

    public class MovieController {
      private RestTemplate restTemplate;
      public User findById(@PathVariable Long id) {
        // Use the placeholder of the RestTemplate
        User user = this.restTemplate.getForObject(
        // ...Movie microservices business...
        return user;

    It can be seen from the code that this one can't be normal controller! Because Sentinel starter will provide a current limit for all HTTP services by default, the Controller can be protected by Sentinel (but there are no rules for configuring protection yet, so it has not been protected yet)!

  • Access http://localhost:20010/actuator/sentinel ,the following results can be obtained:

      "DegradeRules": [],
      "datasources": {},
      "ParamFlowRule": [],
      "SystemRules": [],
      "FlowRules": [],
      "properties": {
          "eager": false,
          "enabled": true,
          "datasource": {},
          "transport": {
              "port": "8719",
              "dashboard": "localhost:200200",
              "heartbeatIntervalMs": null
          "metric": {
              "fileSingleSize": null,
              "fileTotalCount": null,
              "charset": "UTF-8"
          "servlet": {
              "blockPage": null
          "filter": {
              "order": -2147483648,
              "urlPatterns": ["/*"]
          "flow": {
              "coldFactor": "3"
          "log": {
              "dir": null,
              "switchPid": false

At the moment, we don't know what the meaning of the result exposed by /actuator/sentinel is. It doesn't matter, please read on.

Just add the spring-cloud-starter-alibaba-sentinel dependency to your app, and all HTTP interfaces get Sentinel protection! Of course, we currently have no rules for configuring protection for Sentinel.



原文链接:Sentinel Getting Started And Integration of Spring Cloud Alibaba Tutorials

转载,请保留原文地址,谢谢 ~