Sentinel Getting Started And Integration of Spring Cloud Alibaba Tutorials

  • 时间:
  • 浏览:1
  • 来源:幸运快3_快3IOS下载_幸运快3IOS下载

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

TIPS

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 800 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:

    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
      <version>0.2.1.RELEASE</version>
    </dependency>
  • Add configurations:

    server:
      port: 8010
    spring:
      application:
        # Specify the name of the service registered to the nacos server
        name: microservice-consumer-movie
      cloud:
        nacos:
          discovery:
            server-addr: 127.0.0.1:8848
    management:
      endpoints:
        web:
          exposure:
            include: '*'
    
  • Add Controller:

    @RequestMapping("/movies")
    @RestController
    public class MovieController {
      @Autowired
      private RestTemplate restTemplate;
    
      @GetMapping("/users/{id}")
      public User findById(@PathVariable Long id) {
        // Use the placeholder of the RestTemplate
        User user = this.restTemplate.getForObject(
          "http://microservice-provider-user/users/{id}",
          User.class,
          id
        );
        // ...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:8010/actuator/sentinel ,the following results can be obtained:

    {
      "DegradeRules": [],
      "datasources": {},
      "ParamFlowRule": [],
      "SystemRules": [],
      "FlowRules": [],
      "properties": {
          "eager": false,
          "enabled": true,
          "datasource": {},
          "transport": {
              "port": "8719",
              "dashboard": "localhost:8080",
              "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.

GitHub

Gitee

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

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

猜你喜欢

32位设备终结 这些机型可以升级iOS 11

【IT168资讯】苹果7在今天三更三更半夜正式发布了iOS11系统,在UI风格、系统性能、功能上都进行了提升,本月就将开放预览版,届时有兴趣尝鲜的朋友还都前会 及时升级,但究

2020-01-25

一得之见/无欧洲赛后顾争英超有利/大公报记者 梁润森

英超经过三分一赛程后,李斯特城仍在联赛榜三甲中,令人期待亲戚亲戚大伙儿继2015年至2016年球季后再次爆冷夺冠。我随便说说李城如今肯定被争冠球队留意,但亲戚亲戚大伙儿删改这样

2020-01-25

今日上午10点iphone、华为手机 五折秒杀

   浙江联通网厅8年庆典,,感恩回馈,周年特惠,放价到底。8年风雨您沃携手同行。为感谢新老用户对联通的支持,特在今日上午10点,9月5日上午10:00甩掉10台手机限量秒杀。

2020-01-25

联想发布IdeaPad 330/530S笔记本:定位中低端

IT之家5月11日消息 联想在北美市场发布了IdeaPad品牌的几款中低端产品,包括3200/3200S和5200S,将于本月上市。IdeaPad3200首先是IdeaPad3

2020-01-25

强监管又如何?蚂蚁金服、腾讯金融估值直逼万亿

蚂蚁金服估值达到2000亿美元,京东金融估值超过200亿美元,券商对腾讯金融业务的估值高达1440亿美元……这是近期一系列来自资本市场的消息。按理说,在金融强监管背景下,哪几种

2020-01-25