當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
Springboot/Cloud集成Sentinel 和 入门实战
生活随笔
收集整理的這篇文章主要介紹了
Springboot/Cloud集成Sentinel 和 入门实战
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
文章目錄
- 一、Springboot/Cloud集成Sentinel
- 1. spring-cloud-alibaba依賴
- 2. 引入 Sentinel starter
- 3. 配置application.yml
- 3. 接入限流埋點
- 4. 訪問接口
- 5. sentinel控制臺
- 二、入門實戰
- 2.1. 流控管理
- 2.2. 快速訪問請求
一、Springboot/Cloud集成Sentinel
1. spring-cloud-alibaba依賴
Sentinel首先屬于spring-cloud-alibaba下面的組件,因此,第一步要引入spring-cloud-alibaba依賴
文檔:
https://github.com/alibaba/spring-cloud-alibaba/blob/master/README-zh.md
2. 引入 Sentinel starter
官網文檔:
https://github.com/alibaba/spring-cloud-alibaba/blob/master/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/readme-zh.md
3. 配置application.yml
#Springboot/Cloud 應用端口 server:port: 8082#應用名稱 spring:application:name: limitercloud:sentinel:transport:dashboard: localhost:8080 #sentinel控制臺服務端地址3. 接入限流埋點
HTTP 埋點:
Sentinel starter 默認為所有的 HTTP 服務提供了限流埋點,如果只想對 HTTP 服務進行限流,那么只需要引入依賴,無需修改代碼。
4. 訪問接口
第一次要先訪問接口一次,sentinel控制臺才會顯示應用信息
http://localhost:8082/sentinel5. sentinel控制臺
刷新sentinel控制臺顯示
二、入門實戰
2.1. 流控管理
QPS每秒查詢速率
2.2. 快速訪問請求
由于咱們設置的每秒流控是1,每秒只能允許1個請求通過,測試1秒請求數量>1,反饋結果
得出結論當請求數量>1時,會返回Blocked by Sentinel (flow limiting)
總結
以上是生活随笔為你收集整理的Springboot/Cloud集成Sentinel 和 入门实战的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 自动拆箱引发的空指针_02
- 下一篇: SpringBoot Mybatispl