File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed
api-boot-samples/api-boot-sample-rate-limiter Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff 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`后会实时更新到应用程序内。
You can’t perform that action at this time.
0 commit comments