- ubuntu12.04环境下使用kvm ioctl接口实现最简单的虚拟机
- Ubuntu 通过无线网络安装Ubuntu Server启动系统后连接无线网络的方法
- 在Ubuntu上搭建网桥的方法
- ubuntu 虚拟机上网方式及相关配置详解
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.
这篇CFSDN的博客文章Sentinel Dashboard限流规则保存方式由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.
sentinel在限流规则配置方面提供了可视化页面 sentinel dashboard,源码可从github下载,请自行搜索,此处不提供下载链接.
规则持久化后首先触发GatewayFlowRuleController(源码似乎没有,请参考普通规则改造)的/new.json(或)请求,方法会调用publishRules()将本次编辑规则组装后通过远程调用请求gateway/updateRules更新远程服务内存中限流规则,该接口由远程服务UpdateGatewayRuleCommandHandler提供.
UpdateGatewayRuleCommandHandler接收到请求通过调用handle方法,方法通过 。
1
2
3
|
Set<GatewayFlowRule> flowRules = (Set)JSON.parseObject(data,
new
TypeReference<Set<GatewayFlowRule>>() {
},
new
Feature[
0
]);
GatewayRuleManager.loadRules(flowRules);
|
将规则持久化到内存.
Sentinel DashBoard程序流程 。
。
Gateway网关程序流程 。
1
2
3
4
5
|
<
li
ui-sref-active
=
"active"
>
<
a
ui-sref
=
"dashboard.flowV1({app: entry.app})"
>
<
i
class
=
"glyphicon glyphicon-filter"
></
i
> 流控规则
</
a
>
</
li
>
|
改为:
1
2
3
4
5
|
<
li
ui-sref-active
=
"active"
>
<
a
ui-sref
=
"dashboard.flow({app: entry.app})"
>
<
i
class
=
"glyphicon glyphicon-filter"
></
i
> 流控规则
</
a
>
</
li
>
|
2、将webapp\resources\app\scripts\controllers\identity.js中的(主要是将FlowServiceV1改为FlowServiceV2) 。
1
2
3
4
5
|
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) {
|
改为:
1
2
3
4
5
|
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) {
|
FlowRuleNacosProvider.java (从nacos读取配置) 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
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端如果需要读取在此处设置好的配置需要设置的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) 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
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) 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
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 {
//在此处设置nacos服务器的地址
return
ConfigFactory.createConfigService(
"localhost:8848"
);
}
}
|
NacosConfigUtil.java(nacos配置的一些常量) 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
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() {}
}
|
将 。
1
2
3
4
5
6
|
@Autowired
@Qualifier
(
"flowRuleDefaultProvider"
)
private
DynamicRuleProvider<List<FlowRuleEntity>> ruleProvider;
@Autowired
@Qualifier
(
"flowRuleDefaultPublisher"
)
private
DynamicRulePublisher<List<FlowRuleEntity>> rulePublisher;
|
改为:
1
2
3
4
5
6
|
@Autowired
@Qualifier
(
"flowRuleNacosProvider"
)
private
DynamicRuleProvider<List<FlowRuleEntity>> ruleProvider;
@Autowired
@Qualifier
(
"flowRuleNacosPublisher"
)
private
DynamicRulePublisher<List<FlowRuleEntity>> rulePublisher;
|
然后启动之后就可以测试了 。
以上为个人经验,希望能给大家一个参考,也希望大家多多支持我.
原文链接:https://blog.csdn.net/weixin_39195030/article/details/115892923 。
最后此篇关于Sentinel Dashboard限流规则保存方式的文章就讲到这里了,如果你想了解更多关于Sentinel Dashboard限流规则保存方式的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
我需要在 nginx-ingress 版本上允许来自多个来源的请求:http://localhost:4200、http://localhost:4242 等1.7.1.但我无法对多个来源执行此操作,
我正在部署我使用 APIGILITY 开发的 API到 IIS。由于 IIS 不支持 .htaccess,我试图从 .htaccess 文件的内容创建 web.config 文件。我使用 IISv7.
我正在尝试更改上面 css 样式中的“宽度”规则。在“inspect element”中你可以看到宽度是1008px。我不希望它是 1008px 但它不会让我在 css 样式中更改它你可以看到它被“删
外部css赋值有2种方法,我用的是第一种;大多数网站使用第二种方法。我想知道我是否做错了! 第一种方法: 为几乎每个 css 规则创建一个类并在任何地方使用它们。 blah blah .f_
RDF使用 WEB 标识符 (URIs) 来标识资源,使用属性和属性值来描述资源 RDF 资源、属性和属性值 RDF使用 WEB 标识符来标识事物,并通过属性和属性值来描述资源。 关于资源、属性
我想挖掘特定的 rhs 规则。文档中有一个示例证明这是可能的,但仅适用于特定情况(如下所示)。先来一个数据集来说明我的问题: input {b=100002} 0.2500000 0.250000
我想让 nginx 从网站根目录(:http://localhost:8080/)提供一个静态文件,但它为我的代理通行证提供服务;它提供“/”规则而不是“=/”。 这是我的 nginx 配置的样子:
根据gnu make documentation , 如果一个规则通过一次调用生成多个目标(例如,一个配方执行一个带有多个输出文件的工具),你可以使用 '&:' 规则语法来告诉 make。但是,当在多
我已阅读Firebase Documentation并且不明白什么是 .contains()。 以下是文档中 Firebase 数据库的示例规则: { "rules": { "rooms"
关闭。这个问题是opinion-based 。目前不接受答案。 想要改进这个问题吗?更新问题,以便 editing this post 可以用事实和引文来回答它。 . 已关闭 6 年前。 Improv
我正在尝试做一些多态性练习,但我无法弄清楚这种多态性是如何工作的。我没有找到任何关于这种练习的深入信息。希望大家能给我一些解释。 练习1: class Top { public void m(
为了调试复杂的 XSLT 转换,我将其分为几个部分:首先构建 %.1.xml,然后使用它构建 %.2.xml ,最后构建 %.3.xml。一切正常,但如果我要求 Make 构建最后一个,Make 总是
我尝试了 hacerrank 的 slove 练习 Click我不知道如何添加这些规则: ► 它可以包含 4 个一组的数字,并用一个连字符“-”分隔。 ► 不得有 4 个或更多连续重复数字。 这是我的
我正在尝试编写一个小测验,我希望“再试一次”按钮遵循与“else”之前的“if”语句相同的规则 using System; public class Program { public stat
在我的 Spring/Boot Java 项目中,我有一组服务方法,例如以下一个: @Override public Decision create(String name, String descr
我正在阅读 Covariant virtual function .上面写着 假设 B::f 覆盖了虚函数 A::f。如果满足以下所有条件,A::f 和 B::f 的返回类型可能不同: 1) The
我工作的公司想要分发(在公共(public)链接中)具有内部签名的应用程序。我很确定 Apple 否认这种事情,但我在官方文档/契约(Contract)中没有找到任何相关信息。 有谁知道它到底是如何工
我是 CSS 新手。我观察到一个奇怪的 CSS 行为,其中一个元素具有以下 CSS 属性 .container .header{ color: #FFFFFF; font-size: 2em;
这个问题在这里已经有了答案: Is there a CSS selector for elements containing certain text? (21 个答案) 关闭 7 年前。
我有以下 CSS: workoutcal.css: .errorlist{ color:red; } 以下基本模板: base.html: {% load static %} {
我是一名优秀的程序员,十分优秀!