Skip to content

Commit 997adbc

Browse files
committed
接口限流示例
1 parent c624fcc commit 997adbc

File tree

3 files changed

+115
-0
lines changed

3 files changed

+115
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Copyright [2019] [恒宇少年 - 于起宇]
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License");
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~
9+
~ http://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
~
17+
-->
18+
19+
<project xmlns="http://maven.apache.org/POM/4.0.0"
20+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
21+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
22+
<parent>
23+
<artifactId>api-boot-samples</artifactId>
24+
<groupId>org.minbox.framework</groupId>
25+
<version>2.0.6.RELEASE</version>
26+
</parent>
27+
<modelVersion>4.0.0</modelVersion>
28+
29+
<artifactId>api-boot-sample-rate-limiter</artifactId>
30+
<description>
31+
ApiBoot Rate Limiter
32+
单服务接口限流示例
33+
</description>
34+
<dependencies>
35+
<!--SpringBoot Web-->
36+
<dependency>
37+
<groupId>org.springframework.boot</groupId>
38+
<artifactId>spring-boot-starter-web</artifactId>
39+
</dependency>
40+
<!--ApiBoot Rate Limiter-->
41+
<dependency>
42+
<groupId>org.minbox.framework</groupId>
43+
<artifactId>api-boot-starter-rate-limiter</artifactId>
44+
</dependency>
45+
</dependencies>
46+
47+
<!--ApiBoot版本依赖-->
48+
<dependencyManagement>
49+
<dependencies>
50+
<dependency>
51+
<groupId>org.minbox.framework</groupId>
52+
<artifactId>api-boot-dependencies</artifactId>
53+
<version>2.0.6.RELEASE</version>
54+
<type>pom</type>
55+
<scope>import</scope>
56+
</dependency>
57+
</dependencies>
58+
</dependencyManagement>
59+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright [2019] [恒宇少年 - 于起宇]
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
package org.minbox.framework.api.boot.sample;
19+
20+
import org.minbox.framework.api.boot.plugin.rate.limiter.annotation.RateLimiter;
21+
import org.springframework.web.bind.annotation.GetMapping;
22+
import org.springframework.web.bind.annotation.RequestMapping;
23+
import org.springframework.web.bind.annotation.RestController;
24+
25+
/**
26+
* @author:恒宇少年 - 于起宇
27+
* <p>
28+
* DateTime:2019-04-26 14:39
29+
* Blog:http://blog.yuqiyu.com
30+
* WebSite:http://www.jianshu.com/u/092df3f77bca
31+
* Gitee:https://gitee.com/hengboy
32+
* GitHub:https://github.com/hengboy
33+
*/
34+
@RestController
35+
@RequestMapping(value = "/test")
36+
public class RateLimiterSampleController {
37+
/**
38+
* QPS默认为1
39+
*
40+
* @return
41+
*/
42+
@GetMapping(value = "/")
43+
@RateLimiter(QPS = 10)
44+
public String getContent() {
45+
return "访问资源";
46+
}
47+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
spring:
2+
application:
3+
name: api-boot-sample-rate-limiter
4+
5+
api:
6+
boot:
7+
# 配置限流的拦截路径
8+
rate-limiter:
9+
interceptor-url: /**

0 commit comments

Comments
 (0)