Skip to content

Commit b997a98

Browse files
committed
更新流量溢出响应使用文档
1 parent 2e6b9ea commit b997a98

File tree

1 file changed

+31
-0
lines changed
  • api-boot-samples/api-boot-sample-rate-limiter

1 file changed

+31
-0
lines changed

api-boot-samples/api-boot-sample-rate-limiter/README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,37 @@ qps_rate_limiter.{/test/}.tokens
115115

116116
**当然单服务实例也可以使用`Redis`方式**
117117

118+
### 自定义流量溢出响应
119+
120+
流量被限制后可以自定义响应的实体来告知请求发起端,方便做一些业务性质的处理,如下所示:
121+
122+
```java
123+
import org.minbox.framework.api.boot.common.model.ApiBootResult;
124+
import org.minbox.framework.api.boot.plugin.rate.limiter.result.RateLimiterOverFlowResponse;
125+
import org.springframework.stereotype.Component;
126+
127+
/**
128+
* 自定义流量溢出后响应的实体格式
129+
*
130+
* @author:恒宇少年 - 于起宇
131+
* <p>
132+
* DateTime:2019-05-25 16:21
133+
* Blog:http://blog.yuqiyu.com
134+
* WebSite:http://www.jianshu.com/u/092df3f77bca
135+
* Gitee:https://gitee.com/hengboy
136+
* GitHub:https://github.com/hengboy
137+
*/
138+
@Component
139+
public class CustomerResponse implements RateLimiterOverFlowResponse {
140+
@Override
141+
public Object overflow(Object[] methodArgs) {
142+
return ApiBootResult.builder().errorCode("REQUEST_OVER_FLOW").errorMessage("流量被限制.").build();
143+
}
144+
}
145+
```
146+
147+
> `overflow`方法可返回任意类型对象。
148+
118149
### 配置中心支持
119150

120151
为了保证有前瞻性突发流量的处理,`ApiBoot RateLimiter`支持了外部配置中心,在配置中心修改接口限流`QPS`后会实时更新到应用程序内。

0 commit comments

Comments
 (0)