Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
api-service-gateway
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
朱允伟
api-service-gateway
Commits
23a76368
Commit
23a76368
authored
Oct 13, 2021
by
朱允伟
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
<fix> 网关限流添加打印日志
parent
6ed6e111
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
10 additions
and
7 deletions
+10
-7
api-service-gateway/src/main/java/com/zorkdata/apiservice/gateway/filter/GatewayFilter.java
...com/zorkdata/apiservice/gateway/filter/GatewayFilter.java
+6
-0
api-service-gateway/src/main/java/com/zorkdata/apiservice/gateway/schedule/RefreshApiLimitSchedule.java
.../apiservice/gateway/schedule/RefreshApiLimitSchedule.java
+1
-2
api-service-gateway/src/main/resources/application.yml
api-service-gateway/src/main/resources/application.yml
+3
-5
No files found.
api-service-gateway/src/main/java/com/zorkdata/apiservice/gateway/filter/GatewayFilter.java
View file @
23a76368
...
...
@@ -2,6 +2,7 @@ package com.zorkdata.apiservice.gateway.filter;
import
com.zorkdata.apiservice.gateway.schedule.ApiLimitCache
;
import
io.github.bucket4j.Bucket
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.cloud.gateway.filter.GatewayFilterChain
;
import
org.springframework.cloud.gateway.filter.GlobalFilter
;
import
org.springframework.core.Ordered
;
...
...
@@ -10,11 +11,14 @@ import org.springframework.stereotype.Component;
import
org.springframework.web.server.ServerWebExchange
;
import
reactor.core.publisher.Mono
;
import
java.util.logging.Logger
;
/**
* @author zyw
* @create 2021-10-08-18:37
*/
@Component
@Slf4j
public
class
GatewayFilter
implements
GlobalFilter
,
Ordered
{
@Override
...
...
@@ -26,8 +30,10 @@ public class GatewayFilter implements GlobalFilter, Ordered {
}
Bucket
bucket
=
ApiLimitCache
.
BUCKET_CACHE
.
get
(
apiName
);
if
(
null
==
bucket
){
log
.
info
(
"接口:{}没有限流"
,
apiName
);
return
chain
.
filter
(
exchange
);
}
else
{
log
.
info
(
"接口:{}可用调用次数为{}"
,
apiName
,
bucket
.
getAvailableTokens
());
if
(
bucket
.
tryConsume
(
1
))
{
return
chain
.
filter
(
exchange
);
...
...
api-service-gateway/src/main/java/com/zorkdata/apiservice/gateway/schedule/RefreshApiLimitSchedule.java
View file @
23a76368
...
...
@@ -41,8 +41,7 @@ public class RefreshApiLimitSchedule {
@Scheduled
(
cron
=
"0 0 0/1 * * ?"
)
@PostConstruct
private
void
refreshTask
()
{
log
.
info
(
"网关限流刷新执行"
);
String
queryResult
=
restTemplate
.
getForObject
(
url
,
String
.
class
);
try
{
JSONObject
jo
=
new
JSONObject
(
queryResult
);
...
...
api-service-gateway/src/main/resources/application.yml
View file @
23a76368
...
...
@@ -8,8 +8,6 @@ api-service-address:
path
:
/v1/dataService/**
uri
:
http://localhost:6725
url
:
http://localhost:6725/v1/dataService/api/getApiLimit
logging
:
file
:
path
:
gatewaylogs
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