在wso2中没有发生API级别速率限制

时间:2016-09-26 10:53:06

标签: wso2 wso2-am throttling rate-limiting

我正在使用wso2-am 2.0.0来实现API的速率限制。我已经与一个用户发布了API,然后由另一个用户订阅。在订阅时,我正在为该API选择每分钟20个请求的订阅层。此外,用于订阅API的应用程序每分钟限制为50个请求。现在,当我测试API时,在大约50个请求之后才会发生应用程序级别速率限制。未应用API级别限制。理想情况下,用户在20次请求后无法访问API。我正在使用Windows机器来设置wso2服务器和Apache JMeter来向服务器发送请求。我在这里错过了什么?需要一些帮助...

1 个答案:

答案 0 :(得分:0)

这是4MB/s政策。

    @Plan:name('carbon.super_app_BandwidthPolicy')
    @Plan:description('ExecutionPlan for app_BandwidthPolicy')

    @Import('org.wso2.throttle.processed.request.stream:1.0.0')
    define stream RequestStream (messageID string, appKey string, appTier string, subscriptionKey string, apiKey string, apiTier string, subscriptionTier string, resourceKey string, resourceTier string, userId string,  apiContext string, apiVersion string, appTenant string, apiTenant string, appId string, apiName string, propertiesMap string);

    @Export('org.wso2.throttle.globalThrottle.stream:1.0.0')
    define stream GlobalThrottleStream (throttleKey string, isThrottled bool, expiryTimeStamp long);

    FROM RequestStream
    SELECT messageID, (appTenant == 'carbon.super' and appTier == 'BandwidthPolicy') AS isEligible, appKey AS throttleKey, propertiesMap
    INSERT INTO EligibilityStream;

            FROM EligibilityStream[isEligible==true]#throttler:timeBatch(1 min, 0)
            select throttleKey, (sum(cast(map:get(propertiesMap,'messageSize'),'long')) >= 4194304) as isThrottled, expiryTimeStamp group by throttleKey
            INSERT ALL EVENTS into ResultStream;

    from ResultStream#throttler:emitOnStateChange(throttleKey, isThrottled)
    select *
    insert into GlobalThrottleStream;