2016-09-26 47 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