新增限流功能

This commit is contained in:
tanghc
2019-04-11 19:07:53 +08:00
parent f8fd24ce32
commit 59a41de04e
51 changed files with 643 additions and 177 deletions

View File

@@ -57,8 +57,8 @@
<div class="layui-form-item">
<label class="layui-form-label">限流策略</label>
<div class="layui-input-block">
<input type="radio" name="type" value="1" title="漏桶策略" lay-filter="limitTypeFilter">
<input type="radio" name="type" value="2" title="令牌桶策略" lay-filter="limitTypeFilter">
<input type="radio" name="limitType" value="1" title="漏桶策略" lay-filter="limitTypeFilter">
<input type="radio" name="limitType" value="2" title="令牌桶策略" lay-filter="limitTypeFilter">
</div>
</div>
<div class="layui-form-item limit-type type1">

View File

@@ -51,7 +51,7 @@ lib.importJs('../../assets/js/routerole.js')
});
function checkUpdateForm(formData) {
var type = formData.type;
var type = formData.limitType;
if (type == 1) {
if (!/^[1-9]\d*$/.test(formData.execCountPerSecond)) {
layer.alert('每秒可处理请求数必须大于0')
@@ -118,6 +118,8 @@ lib.importJs('../../assets/js/routerole.js')
}
}
var tipType = '<a href="#" onclick="showLimitTypeTip()" title="说明"><i class="layui-icon layui-icon-help"></i></a>'
function renderTable(postData) {
var limitTable = table.render({
elem: '#limitTable'
@@ -129,8 +131,8 @@ lib.importJs('../../assets/js/routerole.js')
{field: 'name', title: '接口名', width: 200}
, {field: 'version', title: '版本号', width: 80}
, {
field: 'type', title: '限流策略', width: 80, templet: function (row) {
return LIMIT_TYPE[row.type + ''];
field: 'limitType', title: '限流策略 ' + tipType, width: 100, templet: function (row) {
return LIMIT_TYPE[row.limitType + ''];
}
}
, {
@@ -139,11 +141,11 @@ lib.importJs('../../assets/js/routerole.js')
return '--'
}
var html = [];
if (row.type == 1) {
if (row.limitType == 1) {
html.push('每秒可处理请求数:' + row.execCountPerSecond);
html.push('subCode' + row.limitCode);
html.push('subMsg' + row.limitMsg);
} else if(row.type == 2) {
} else if(row.limitType == 2) {
html.push('令牌桶容量:' + row.tokenBucketCount);
}
return html.join('');
@@ -173,7 +175,7 @@ lib.importJs('../../assets/js/routerole.js')
updateForm.setData(data);
$('.limit-type').hide();
$('.type' + data.type).show();
$('.type' + data.limitType).show();
layer.open({
type: 1
@@ -191,4 +193,20 @@ lib.importJs('../../assets/js/routerole.js')
RouteRole.loadAllRole(form, 'roleArea');
});
});
function showLimitTypeTip() {
var leakyRemark = '漏桶策略:每秒处理固定数量的请求,超出请求返回错误信息。';
var tokenRemark = '令牌桶策略:每秒放置固定数量的令牌数,不足的令牌数做等待处理,直到拿到令牌为止。';
var content = '<div style="font-size: 14px;">'
+ leakyRemark
+ '<br>'
+ tokenRemark
+ '</div>';
layer.open({
title: '限流策略说明'
,area: ['600px', 'auto']
,content: content
});
}

View File

@@ -88,7 +88,7 @@ public class LimitApi {
private ConfigRouteLimit getDefaultLimit() {
ConfigRouteLimit configRouteLimit = new ConfigRouteLimit();
configRouteLimit.setType(LimitEnum.TYPE_LEAKY_BUCKET.getVal());
configRouteLimit.setLimitType(LimitEnum.TYPE_LEAKY_BUCKET.getVal());
configRouteLimit.setLimitStatus(LimitEnum.STATUS_CLOSE.getVal());
return configRouteLimit;
}

View File

@@ -21,10 +21,10 @@ public class LimitParam {
@NotBlank(message = "serviceId can not null")
private String serviceId;
/** 限流策略1漏桶策略2令牌桶策略, 数据库字段type */
/** 限流策略1漏桶策略2令牌桶策略, 数据库字段:limit_type */
@ApiDocField(description = "限流策略1漏桶策略2令牌桶策略")
@NotNull
private Byte type;
private Byte limitType;
/** 每秒可处理请求数, 数据库字段exec_count_per_second */
@ApiDocField(description = "每秒可处理请求数")

View File

@@ -11,7 +11,7 @@ import lombok.Data;
@Data
public class LimitVO {
@ApiDocField(description = "是否存在记录")
private int hasRecord;
private Integer hasRecord;
@ApiDocField(description = "路由id")
private String routeId;
@@ -32,10 +32,10 @@ public class LimitVO {
private String serviceId;
/**
* 限流策略1漏桶策略2令牌桶策略, 数据库字段type
* 限流策略1漏桶策略2令牌桶策略, 数据库字段:limit_type
*/
@ApiDocField(description = "限流策略1漏桶策略2令牌桶策略")
private Byte type;
private Byte limitType;
/**
* 每秒可处理请求数, 数据库字段exec_count_per_second

View File

@@ -10,8 +10,8 @@ public class RouteConfigDto {
private String routeId;
/** 限流策略1漏桶策略2令牌桶策略, 数据库字段type */
private Byte type;
/** 限流策略1漏桶策略2令牌桶策略, 数据库字段:limit_type */
private Byte limitType;
/** 每秒可处理请求数, 数据库字段exec_count_per_second */
private Integer execCountPerSecond;

View File

@@ -32,8 +32,8 @@ public class ConfigRouteLimit {
/** serviceId, 数据库字段service_id */
private String serviceId;
/** 限流策略1漏桶策略2令牌桶策略, 数据库字段type */
private Byte type;
/** 限流策略1漏桶策略2令牌桶策略, 数据库字段:limit_type */
private Byte limitType;
/** 每秒可处理请求数, 数据库字段exec_count_per_second */
private Integer execCountPerSecond;