This documentation is for WSO2 API Manager 1.10.0 View documentation for the latest release.
Adding Customized Throttling Tiers - API Manager 1.10.0 - WSO2 Documentation
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 10 Next »

API Manager admins can add new throttling tiers and define extra properties to throttling tiers using the management console as discussed below. For a description of throttling tiers, see API-level throttling.

You can configure API Manager to have a new throttling tier addition to the existing throttling tiers available by default. 

Adding a new throttling tier

Let's see how to add a new throttling tier to the API Manager.

  1. Log in to the API Manager's Management Console and select Browse under Resources menu.
  2. Select the file: /_system/governance/apimgt/applicationdata/tiers.xml.

  3. In the Contents panel, click Edit as text link and the throttling policy opens.

  4. You can add a new policy configuration by editing the XML code. For example, we have added a new tier called Platinum by including the following XML code block soon after the <throttle:MediatorThrottleAssertion> element.

    • Tier DisplayName:  You can add this optional attribute to each throttle ID of tiers.xml file in order to decouple the throttle policy name defined in tiers.xml from the tier name showing in APIPublisher/Store UIs. That is, a user can add a different throttle display name to appear in APIPublisher/Store UIs without changing the throttle ID policy name. The configuration below has a displayName as platino for the throttle value platinum. This value is displayed in APIPublisher/Store apps.
    • Tier Attributes:  In the configuration below, there's a commented out XML section starting from the XML tag  <throttle:Attributes> . You can use it to define additional attributes related to each throttling tier definition. For example, if the throttling tier  Platinum  has attributes called  PaymentPlan  and  Availability , first uncomment the  <throttle:Attributes>  section and then define the new attributes as follows:

     

    <wsp:Policy>
     <throttle:ID throttle:type="ROLE" throttle:displayName="platino">Platinum</throttle:ID>
       <wsp:Policy>
         <throttle:Control>
            <wsp:Policy>
              <throttle:MaximumCount>50</throttle:MaximumCount>
                 <throttle:UnitTime>60000</throttle:UnitTime>
                   <!--It's possible to define tier level attributes as below for each tier level.For eg:Payment Plan for a tier-->
                      <wsp:Policy>
                         <throttle:Attributes>
                            <!--throttle:Attribute1>xxxx</throttle:Attribute1-->
                            <!--throttle:Attribute2>xxxx</throttle:Attribute2-->
                            <throttle:PaymentPlan>monthly</throttle:PaymentPlan>
                            <throttle:Availability>FullTime</throttle:Availability>
                         </throttle:Attributes>
                      </wsp:Policy>
            </wsp:Policy>
         </throttle:Control>
       </wsp:Policy>
    </wsp:Policy>
  5. After the edits, click Save Content. Your new throttling policy (Platinum) is now successfully saved in the repository used by WSO2 API Manager. You can view this new throttle tier available for selection when creating a new API through the API Publisher.

Multi-layer throttling

Multi-layer throttling is applying different throttling policies at the same time for a single API. The API Manager can be extended to support multiple throttling policies.

The following example shows how to have two throttling policies for a single API at a given time. The table below shows the throttling information of the two throttling policies:

Tier

throttle-l1

throttle-l2
free300 per month5 per 3 minutes
Silver2000 per month1 per 5 seconds
Gold - UnlimitedUnlimitedUnlimited

To engage the two throttling layers, you add two throttling tier definitions and engage them to the API using the steps below:

  1. Go to the Synapse configuration file of the particular API located in < AM_HOME>/repository/deployment/server/synapse-configs/default/api.
  2. Copy the following content inside the <handlers> section in the API configuration.

    <handler class="org.wso2.carbon.apimgt.gateway.handlers.security.APIAuthenticationHandler"/>
    <handler class="org.wso2.carbon.apimgt.gateway.handlers.throttling.APIThrottleHandler">
    	<property name="id" value="B"/>
    	<property name="policyKey" value="gov:/apimgt/applicationdata/throttling-l2.xm"/>
    </handler>
    <handler class="org.wso2.carbon.apimgt.gateway.handlers.throttling.APIThrottleHandler">
    	<property name="id" value="A"/>
    	<property name="policyKey" value="gov:/apimgt/applicationdata/tiers.xml"/>
    </handler>
  3. Replace the existing content of the  /_system/governance/apimgt/applicationdata/tiers.xml file with following content.

    throttling-l1.xml
    <wsp:Policy xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:throttle="http://www.wso2.org/products/wso2commons/throttle">
        <throttle:MediatorThrottleAssertion>
            <wsp:Policy>
                <throttle:ID throttle:type="ROLE">Gold</throttle:ID>
                <wsp:Policy>
                    <throttle:Control>
                        <wsp:Policy>
                            <throttle:MaximumCount>20</throttle:MaximumCount>
                            <throttle:UnitTime>60000</throttle:UnitTime>
                        </wsp:Policy>
                    </throttle:Control>
                </wsp:Policy>
            </wsp:Policy>
            <wsp:Policy>
                <throttle:ID throttle:type="ROLE">Silver</throttle:ID>
                <wsp:Policy>
                    <throttle:Control>
                        <wsp:Policy>
                            <throttle:MaximumCount>2000</throttle:MaximumCount>
                            <throttle:UnitTime>2592000000</throttle:UnitTime>
                        </wsp:Policy>
                    </throttle:Control>
                </wsp:Policy>
            </wsp:Policy>
            <wsp:Policy>
                <throttle:ID throttle:type="ROLE">free</throttle:ID>
                <wsp:Policy>
                    <throttle:Control>
                        <wsp:Policy>
                            <throttle:MaximumCount>300</throttle:MaximumCount>
                            <throttle:UnitTime>2592000000</throttle:UnitTime>
                        </wsp:Policy>
                    </throttle:Control>
                </wsp:Policy>
            </wsp:Policy>
            <wsp:Policy>
                <throttle:ID throttle:type="ROLE">Unauthenticated</throttle:ID>
                <wsp:Policy>
                    <throttle:Control>
                        <wsp:Policy>
                            <throttle:MaximumCount>60</throttle:MaximumCount>
                            <throttle:UnitTime>60000</throttle:UnitTime>
                        </wsp:Policy>
                    </throttle:Control>
                </wsp:Policy>
            </wsp:Policy>
        </throttle:MediatorThrottleAssertion>
    </wsp:Policy>
  4. Create an XML as throttling-l2.xml with the following content and add it to /_system/governance/apimgt/applicationdata registry location.
    The code adds two policies for each role (free, Silver, Gold) and engages them to the APIs with different keys. Both throttling layers execute in runtime sequentially. 

    throttling-l2.xml
    <wsp:Policy xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:throttle="http://www.wso2.org/products/wso2commons/throttle">
        <throttle:MediatorThrottleAssertion>
            <wsp:Policy>
                <throttle:ID throttle:type="ROLE">Gold</throttle:ID>
                <wsp:Policy>
                    <throttle:Control>
                        <wsp:Policy>
                            <throttle:MaximumCount>20</throttle:MaximumCount>
                            <throttle:UnitTime>60000</throttle:UnitTime>
                        </wsp:Policy>
                    </throttle:Control>
                </wsp:Policy>
            </wsp:Policy>
            <wsp:Policy>
                <throttle:ID throttle:type="ROLE">Silver</throttle:ID>
                <wsp:Policy>
                    <throttle:Control>
                        <wsp:Policy>
                            <throttle:MaximumCount>1</throttle:MaximumCount>
                            <throttle:UnitTime>5000</throttle:UnitTime>
                        </wsp:Policy>
                    </throttle:Control>
                </wsp:Policy>
            </wsp:Policy>
            <wsp:Policy>
                <throttle:ID throttle:type="ROLE">Free</throttle:ID>
                <wsp:Policy>
                    <throttle:Control>
                        <wsp:Policy>
                            <throttle:MaximumCount>5</throttle:MaximumCount>
                            <throttle:UnitTime>180000</throttle:UnitTime>
                        </wsp:Policy>
                    </throttle:Control>
                </wsp:Policy>
            </wsp:Policy>
            <wsp:Policy>
                <throttle:ID throttle:type="ROLE">Unauthenticated</throttle:ID>
                <wsp:Policy>
                    <throttle:Control>
                        <wsp:Policy>
                            <throttle:MaximumCount>60</throttle:MaximumCount>
                            <throttle:UnitTime>60000</throttle:UnitTime>
                        </wsp:Policy>
                    </throttle:Control>
                </wsp:Policy>
            </wsp:Policy>
        </throttle:MediatorThrottleAssertion>
    </wsp:Policy>
  • No labels