最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Sentinel Dashboard限流規(guī)則保存方式

 更新時(shí)間:2021年06月25日 11:51:53   作者:y&m  
這篇文章主要介紹了Sentinel Dashboard限流規(guī)則保存方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

Sentinel Dashboard限流規(guī)則保存

sentinel在限流規(guī)則配置方面提供了可視化頁(yè)面 sentinel dashboard,源碼可從github下載,請(qǐng)自行搜索,此處不提供下載鏈接。

規(guī)則持久化后首先觸發(fā)GatewayFlowRuleController(源碼似乎沒(méi)有,請(qǐng)參考普通規(guī)則改造)的/new.json(或)請(qǐng)求,方法會(huì)調(diào)用publishRules()將本次編輯規(guī)則組裝后通過(guò)遠(yuǎn)程調(diào)用請(qǐng)求gateway/updateRules更新遠(yuǎn)程服務(wù)內(nèi)存中限流規(guī)則,該接口由遠(yuǎn)程服務(wù)UpdateGatewayRuleCommandHandler提供。

UpdateGatewayRuleCommandHandler接收到請(qǐng)求通過(guò)調(diào)用handle方法,方法通過(guò)

Set<GatewayFlowRule> flowRules = (Set)JSON.parseObject(data, new TypeReference<Set<GatewayFlowRule>>() {
            }, new Feature[0]);
            GatewayRuleManager.loadRules(flowRules);

將規(guī)則持久化到內(nèi)存。

具體請(qǐng)參考以下流程圖

Sentinel DashBoard程序流程

 在這里插入圖片描述

Gateway網(wǎng)關(guān)程序流程

在這里插入圖片描述

sentinel dashboard 限流規(guī)則持久化到nacos

1、將webapp/resources/app/scripts/directives/sidebar/sidebar.html中的

<li ui-sref-active="active">
<a ui-sref="dashboard.flowV1({app: entry.app})">
<i class="glyphicon glyphicon-filter"></i>&nbsp;&nbsp;流控規(guī)則
</a>
</li>

改為:

<li ui-sref-active="active">
<a ui-sref="dashboard.flow({app: entry.app})">
<i class="glyphicon glyphicon-filter"></i>&nbsp;&nbsp;流控規(guī)則
</a>
</li>

2、將webapp\resources\app\scripts\controllers\identity.js中的(主要是將FlowServiceV1改為FlowServiceV2)

app.controller('IdentityCtl', ['$scope', '$stateParams', 'IdentityService',
  'ngDialog', 'FlowServiceV1', 'DegradeService', 'AuthorityRuleService', 'ParamFlowService', 'MachineService',
  '$interval', '$location', '$timeout',
  function ($scope, $stateParams, IdentityService, ngDialog,
    FlowService, DegradeService, AuthorityRuleService, ParamFlowService, MachineService, $interval, $location, $timeout) {

改為:

app.controller('IdentityCtl', ['$scope', '$stateParams', 'IdentityService',
  'ngDialog', 'FlowServiceV2', 'DegradeService', 'AuthorityRuleService', 'ParamFlowService', 'MachineService',
  '$interval', '$location', '$timeout',
  function ($scope, $stateParams, IdentityService, ngDialog,
    FlowService, DegradeService, AuthorityRuleService, ParamFlowService, MachineService, $interval, $location, $timeout) {

3、將下面的四個(gè)文件全部拷貝到src/main/java的com.alibaba.csp.sentinel.dashboard.rule包下

FlowRuleNacosProvider.java (從nacos讀取配置)

 package com.alibaba.csp.sentinel.dashboard.rule;
 import java.util.ArrayList;
 import java.util.List;
 import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.FlowRuleEntity;
 import com.alibaba.csp.sentinel.dashboard.rule.DynamicRuleProvider;
 import com.alibaba.csp.sentinel.datasource.Converter;
 import com.alibaba.csp.sentinel.util.StringUtil;
 import com.alibaba.nacos.api.config.ConfigService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 @Component("flowRuleNacosProvider")
 public class FlowRuleNacosProvider implements DynamicRuleProvider<List<FlowRuleEntity>> {
  @Autowired
  private ConfigService configService;
  @Autowired
  private Converter<String, List<FlowRuleEntity>> converter;
  @Override
  public List<FlowRuleEntity> getRules(String appName) throws Exception {
   // app端如果需要讀取在此處設(shè)置好的配置需要設(shè)置的GROUP和dataId 需要和這里保持一致
   String group = NacosConfigUtil.GROUP_ID;
   String dataId = appName + NacosConfigUtil.FLOW_DATA_ID_POSTFIX;
   String rules = configService.getConfig(dataId, group, 3000);
   if (StringUtil.isEmpty(rules)) {
    return new ArrayList<>();
   }
   return converter.convert(rules);
  }
 }

FlowRuleNacosPublisher.java (將修改后的配置同步到nacos)

 package com.alibaba.csp.sentinel.dashboard.rule; 
 import java.util.List;
 import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.FlowRuleEntity;
 import com.alibaba.csp.sentinel.dashboard.rule.DynamicRulePublisher;
 import com.alibaba.csp.sentinel.datasource.Converter;
 import com.alibaba.csp.sentinel.util.AssertUtil;
 import com.alibaba.nacos.api.config.ConfigService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 @Component("flowRuleNacosPublisher")
 public class FlowRuleNacosPublisher implements DynamicRulePublisher<List<FlowRuleEntity>> {
 
   @Autowired
      private ConfigService configService;
      @Autowired
      private Converter<List<FlowRuleEntity>, String> converter;
 
      @Override
      public void publish(String app, List<FlowRuleEntity> rules) throws Exception {
          AssertUtil.notEmpty(app, "app name cannot be empty");
          if (rules == null) {
              return;
          }
          //需要和FlowRuleNacosProvider保持一致
          String group = NacosConfigUtil.GROUP_ID;
    String dataId = appName + NacosConfigUtil.FLOW_DATA_ID_POSTFIX;
          configService.publishConfig(dataId , group , converter.convert(rules));
      }
    
 }

NacosConfig.java(初始化nacos的nacosConfigService)

 package com.alibaba.csp.sentinel.dashboard.rule; 
 import java.util.List;
 import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.DegradeRuleEntity;
 import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.FlowRuleEntity;
 import com.alibaba.csp.sentinel.datasource.Converter;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.nacos.api.config.ConfigFactory;
 import com.alibaba.nacos.api.config.ConfigService;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 @Configuration
 public class NacosConfig {
 
     @Bean
     public Converter<List<FlowRuleEntity>, String> flowRuleEntityEncoder() {
         return JSON::toJSONString;
     }
     @Bean
     public Converter<String, List<FlowRuleEntity>> flowRuleEntityDecoder() {
         return s -> JSON.parseArray(s, FlowRuleEntity.class);
     }
     @Bean
     public Converter<List<DegradeRuleEntity>, String> degradeRuleEntityEncoder() {
         return JSON::toJSONString;
     }
     @Bean
     public Converter<String, List<DegradeRuleEntity>> degradeRuleEntityDecoder() {
         return s -> JSON.parseArray(s, DegradeRuleEntity.class);
     }
     @Bean
     public ConfigService nacosConfigService() throws Exception {
      //在此處設(shè)置nacos服務(wù)器的地址
         return ConfigFactory.createConfigService("localhost:8848");
     }
 }

NacosConfigUtil.java(nacos配置的一些常量)

package com.alibaba.csp.sentinel.dashboard.rule;
 public final class NacosConfigUtil { 
     public static final String GROUP_ID = "SENTINEL_GROUP";     
     public static final String FLOW_DATA_ID_POSTFIX = "-flow-rules";
     public static final String PARAM_FLOW_DATA_ID_POSTFIX = "-param-rules";
     public static final String CLUSTER_MAP_DATA_ID_POSTFIX = "-cluster-map";
     public static final String DEGRADE_DATA_ID_POSTFIX = "-degrade-rules";
     /**
      * cc for `cluster-client`
      */
     public static final String CLIENT_CONFIG_DATA_ID_POSTFIX = "-cc-config";
     /**
      * cs for `cluster-server`
      */
     public static final String SERVER_TRANSPORT_CONFIG_DATA_ID_POSTFIX = "-cs-transport-config";
     public static final String SERVER_FLOW_CONFIG_DATA_ID_POSTFIX = "-cs-flow-config";
     public static final String SERVER_NAMESPACE_SET_DATA_ID_POSTFIX = "-cs-namespace-set";
 
     private NacosConfigUtil() {}
 }

4、修改com.alibaba.csp.sentinel.dashboard.controller.v2.FlowControllerV2

    @Autowired
    @Qualifier("flowRuleDefaultProvider")
    private DynamicRuleProvider<List<FlowRuleEntity>> ruleProvider;
    @Autowired
    @Qualifier("flowRuleDefaultPublisher")
    private DynamicRulePublisher<List<FlowRuleEntity>> rulePublisher;

改為:

    @Autowired
    @Qualifier("flowRuleNacosProvider")
    private DynamicRuleProvider<List<FlowRuleEntity>> ruleProvider;
    @Autowired
    @Qualifier("flowRuleNacosPublisher")
    private DynamicRulePublisher<List<FlowRuleEntity>> rulePublisher;

然后啟動(dòng)之后就可以測(cè)試了

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • Java對(duì)List進(jìn)行排序的方法總結(jié)

    Java對(duì)List進(jìn)行排序的方法總結(jié)

    在Java中,對(duì)List進(jìn)行排序是一項(xiàng)常見(jiàn)的任務(wù),Java提供了多種方法來(lái)對(duì)List中的元素進(jìn)行排序,本文將詳細(xì)介紹如何使用Java來(lái)實(shí)現(xiàn)List的排序操作,涵蓋了常用的排序方法和技巧,需要的朋友可以參考下
    2024-07-07
  • SpringBoot集成PageHelper及使用方法詳解

    SpringBoot集成PageHelper及使用方法詳解

    這篇文章主要介紹了SpringBoot集成PageHelper及使用方法詳解,PageHelper 是一個(gè)開(kāi)源的 Java 分頁(yè)插件,它可以幫助開(kāi)發(fā)者簡(jiǎn)化分頁(yè)操作,本文提供部分相關(guān)代碼,需要的朋友可以參考下
    2023-10-10
  • Java的MyBatis框架中實(shí)現(xiàn)多表連接查詢和查詢結(jié)果分頁(yè)

    Java的MyBatis框架中實(shí)現(xiàn)多表連接查詢和查詢結(jié)果分頁(yè)

    這篇文章主要介紹了Java的MyBatis框架中實(shí)現(xiàn)多表連接查詢和查詢結(jié)果分頁(yè),借助MyBatis框架中帶有的動(dòng)態(tài)SQL查詢功能可以比普通SQL查詢做到更多,需要的朋友可以參考下
    2016-04-04
  • 淺析Java中的GC垃圾回收器的意義及與GC的交互

    淺析Java中的GC垃圾回收器的意義及與GC的交互

    這篇文章主要介紹了Java中的GC垃圾回收器的意義及與其的交互,GC是Java虛擬機(jī)JVM的一項(xiàng)重要特性,需要的朋友可以參考下
    2015-12-12
  • Java Stream流知識(shí)總結(jié)

    Java Stream流知識(shí)總結(jié)

    這篇文章主要介紹了Java Stream流的相關(guān)知識(shí),文中講解非常細(xì)致,代碼幫助大家更好的理解和學(xué)習(xí),感興趣的朋友可以了解下
    2020-06-06
  • 淺析Java中為什么要設(shè)計(jì)包裝類

    淺析Java中為什么要設(shè)計(jì)包裝類

    我們知道Java是一個(gè)面相對(duì)象的編程語(yǔ)言,基本類型并不具有對(duì)象的性質(zhì),為了讓基本類型也具有對(duì)象的特征,就出現(xiàn)了包裝類型,它相當(dāng)于將基本類型“包裝起來(lái)”,使得它具有了對(duì)象的性質(zhì),并且為其添加了屬性和方法,豐富了基本類型的操作
    2021-06-06
  • java的jdbc簡(jiǎn)單封裝方法

    java的jdbc簡(jiǎn)單封裝方法

    本篇文章是對(duì)java的jdbc簡(jiǎn)單封裝方法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
    2015-07-07
  • 詳解Java 反射和反射的應(yīng)用場(chǎng)景

    詳解Java 反射和反射的應(yīng)用場(chǎng)景

    這篇文章主要介紹了Java 反射和反射的應(yīng)用場(chǎng)景的相關(guān)資料,幫助大家更好的理解和學(xué)習(xí)Java反射的相關(guān)知識(shí),感興趣的朋友可以了解下
    2020-08-08
  • springboot結(jié)合mysql主從來(lái)實(shí)現(xiàn)讀寫(xiě)分離的方法示例

    springboot結(jié)合mysql主從來(lái)實(shí)現(xiàn)讀寫(xiě)分離的方法示例

    這篇文章主要介紹了springboot結(jié)合mysql主從來(lái)實(shí)現(xiàn)讀寫(xiě)分離的方法示例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2021-04-04
  • 一文詳解Java的餓漢和懶漢設(shè)計(jì)模式

    一文詳解Java的餓漢和懶漢設(shè)計(jì)模式

    這篇文章主要為大家詳細(xì)介紹了Java設(shè)計(jì)模式中的的餓漢模式和懶漢模式,文中的示例代碼講解詳細(xì),對(duì)我們學(xué)習(xí)Java有一定的幫助,需要的可以參考一下
    2022-12-12

最新評(píng)論

教育| 福清市| 屏东市| 灵璧县| 黄浦区| 中江县| 南皮县| 六安市| 大同县| 莆田市| 雷山县| 千阳县| 杂多县| 万源市| 来宾市| 固镇县| 滦南县| 台前县| 木兰县| 普兰店市| 策勒县| 阿拉善右旗| 青冈县| 八宿县| 安康市| 集安市| 雷波县| 巴彦淖尔市| 周至县| 开化县| 阳西县| 怀仁县| 靖安县| 金沙县| 达拉特旗| 杨浦区| 九台市| 新津县| 乐都县| 义乌市| 都昌县|