2016-09-26 48 views
2

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

+0

您是否使用默认高级遏制? – Bee

+0

在发布API时,我已经设置了这个... 高级限制策略:我已经选择了“应用于API级别”,并从下拉菜单中将该值设置为“Unlimited”。 – siddhesh

+0

如果您正确创建了新的订阅策略(每分钟20个),它应该按预期进行调节。你可以在'wso2am-2.0.0/repository/deployment/server/executionplans'中发布相应的策略文件吗? – Bee

回答

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; 
+0

谢谢你:)。这是我想要的 – siddhesh