SpringBoot + SpringCloud + Feign + Sentinel 集成實現接口限流監控-Demo

SpringBoot + SpringCloud + Feign + Sentinel 集成實現接口限流監控

SpringBoot版本:1.5.13.RELEASE

SpringCloud版本:Edgware.SR4

Sentinel詳情介紹版本:0.1.2.RELEASE 是集成了spring-cloud-alibaba

註冊中心-eureka

服務提供-producer

服務消費-consumer

Sentinel Dashbord

Demo使用說明:

  1. Dashboard啓動:
    java -Dserver.port=8080 -jar sentinel-dashboard.jar
    官網參考
  2. 啓動erueka --> 啓動Producer --> 啓動Consumer
  3. 展示圖片:
    [外鏈圖片轉存失敗(img-nHZ3Jf9h-1564655959756)(https://github.com/Xlinlin/SpringCloud-Demo/blob/master/SpringCloud-Sentinel/img/sentinel-dashbord-producer.png)]
    [外鏈圖片轉存失敗(img-HTUtBRua-1564655959762)(https://github.com/Xlinlin/SpringCloud-Demo/blob/master/SpringCloud-Sentinel/img/sentinel-dashbord-consumer.png)]

簡要配置說明:

  1. dashboard啓動後,客戶端接入:
     properties配置:
     # Sentinel dashbord 數據交互端口,注意單機多服務部署端口衝突
     spring.cloud.sentinel.transport.port=8729
     # sentinel  dashbord地址
     spring.cloud.sentinel.transport.dashboard=192.168.206.212:8880
     
     pom文件引入(自動引入相關依賴包):
     <dependency>
         <groupId>org.springframework.cloud</groupId>
         <artifactId>spring-cloud-alibaba-sentinel</artifactId>
         <version>0.1.2.RELEASE</version>
     </dependency>
    
    
  2. producer和consumer使用sentinel僅引入 上一步中的pom文件即可
  3. feign的支持:
     pom引入:
     <dependency>
         <groupId>org.springframework.cloud</groupId>
         <artifactId>spring-cloud-starter-openfeign</artifactId>
         <version>1.4.7.RELEASE</version>
     </dependency>
    
     開啓sentinel支持
     # 使用阿里 sentinel監控
     feign.sentinel.enabled=true
    
    

重要提示:

  1. Sentinel版本要與springboot和springcloud大版本一致,否則會出現不可預見的異常
  2. 接入到dashbord後,要請求下url,然後稍等等個1分鐘左右才能到控制檯,不要着急

Github地址

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章