Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
spring-boot-starter-dsp
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
shenjiaqing
spring-boot-starter-dsp
Commits
2fe82b29
Commit
2fe82b29
authored
May 19, 2022
by
shenjiaqing
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
提交代码
parent
f75177fc
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
8 additions
and
13 deletions
+8
-13
build.gradle
build.gradle
+1
-1
LimitAspect.java
...uiba/spring/boot/starter/dsp/rateLimiter/LimitAspect.java
+5
-9
TokenBucketLimiter.java
...ring/boot/starter/dsp/rateLimiter/TokenBucketLimiter.java
+2
-3
No files found.
build.gradle
View file @
2fe82b29
...
...
@@ -38,7 +38,7 @@ allprojects {
}
group
=
"cn.com.duiba.boot"
version
=
"0.0.
80-sjq-SNAPSHOT
"
version
=
"0.0.
43
"
}
subprojects
{
...
...
spring-boot-starter-dsp-rateLimiter/src/main/java/cn/com/duiba/spring/boot/starter/dsp/rateLimiter/LimitAspect.java
View file @
2fe82b29
...
...
@@ -26,8 +26,7 @@ public class LimitAspect {
private
final
static
Integer
REDIS_NODE_NUM
=
4
;
static
{
map
.
put
(
"rate.limit:com.duiba.tuia.adx.web.service.algo.impl.AdxAlgoServiceImpl-hello-limit"
,
new
AtomicLong
());
map
.
put
(
"rate.limit:cn.com.duiba.tuia.algo.engine.adx.service.v4.AdxAlgoService-execute-limit1"
,
new
AtomicLong
());
redisNodeIndex
.
put
(
0L
,
14
);
redisNodeIndex
.
put
(
1L
,
18
);
redisNodeIndex
.
put
(
2L
,
296
);
...
...
@@ -72,13 +71,10 @@ public class LimitAspect {
return
joinPoint
.
proceed
();
}
StringBuilder
stringBuilder
=
new
StringBuilder
();
stringBuilder
.
append
(
"rate.limit:"
).
append
(
targetClass
.
getName
()).
append
(
"-"
)
.
append
(
method
.
getName
()).
append
(
"-"
)
.
append
(
rateLimit
.
key
());
String
commonRedisKey
=
stringBuilder
.
toString
();
String
commonRedisKey
=
"rate.limit:"
+
targetClass
.
getName
()
+
"-"
+
method
.
getName
()
+
"-"
+
rateLimit
.
key
();
long
index
=
map
.
get
(
commonRedisKey
).
getAndIncrement
()
%
REDIS_NODE_NUM
;
...
...
spring-boot-starter-dsp-rateLimiter/src/main/java/cn/com/duiba/spring/boot/starter/dsp/rateLimiter/TokenBucketLimiter.java
View file @
2fe82b29
...
...
@@ -2,7 +2,6 @@ package cn.com.duiba.spring.boot.starter.dsp.rateLimiter;
import
com.google.common.collect.Lists
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.redis.core.StringRedisTemplate
;
import
org.springframework.data.redis.core.script.DefaultRedisScript
;
import
javax.annotation.Resource
;
...
...
@@ -11,10 +10,10 @@ import java.util.Objects;
@Slf4j
public
class
TokenBucketLimiter
{
@Resource
(
name
=
"redis03StringRedisTemplate"
)
@Resource
private
StringRedisTemplate
stringRedisTemplate
;
@
Autowired
@
Resource
private
DefaultRedisScript
<
Long
>
redisLuaScript
;
boolean
acquire
(
String
key
,
TokenBucketLimiterPolicy
policy
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment