liubao68 commented on a change in pull request #2061:
URL:
https://github.com/apache/servicecomb-java-chassis/pull/2061#discussion_r527332686
##########
File path:
handlers/handler-flowcontrol-qps/src/main/java/org/apache/servicecomb/qps/ProviderQpsFlowControlHandler.java
##########
@@ -31,36 +36,48 @@
.setBucketKeyPrefix(Config.PROVIDER_BUCKET_KEY_PREFIX)
.setGlobalQpsStrategy(Config.PROVIDER_LIMIT_KEY_GLOBAL,
Config.PROVIDER_BUCKET_KEY_GLOBAL);
+ private PolicyService policyService = new PolicyServiceImpl();
+
+ private LeakyBucketStrategy qpsStrategy = new LeakyBucketStrategy();
+
@Override
public void handle(Invocation invocation, AsyncResponse asyncResp) throws
Exception {
- if (invocation.getHandlerIndex() > 0) {
- // handlerIndex > 0, which means this handler is executed in handler
chain.
- // As this flow control logic has been executed in advance, this time it
should be ignored.
- invocation.next(asyncResp);
- return;
- }
-
// The real executing position of this handler is no longer in handler
chain, but in AbstractRestInvocation.
// Therefore, the Invocation#next() method should not be called below.
if (!Config.INSTANCE.isProviderEnabled()) {
return;
}
+ if (isRateLimiting(invocation, asyncResp)) {
+ CommonExceptionData errorData = new CommonExceptionData("rejected by qps
flowcontrol");
+ asyncResp.producerFail(new
InvocationException(QpsConst.TOO_MANY_REQUESTS_STATUS, errorData));
+ }
+ }
+
+ private boolean isRateLimiting(Invocation invocation, AsyncResponse
asyncResp) throws Exception {
+ String match = invocation.getContext().get(RequestMarkHandler.MARK_KEY);
Review comment:
I mean invocation addLocalContext
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]