Copyright © Cloud Software Group, Inc. All Rights Reserved
Copyright © Cloud Software Group, Inc. All Rights Reserved


Chapter 9 Throttles : Content Based Throttles

Content Based Throttles
TIBCO API Exchange Gateway allows you to create custom throttles based on the content information in the facade request.
For any throttle configuration specified in the Config UI, you can extend a throttle configuration to create a monitor. Using this monitor, you enforce a custom throttle policy based on the data of the message. You can create a monitor to extract a value based on the data in the request message. This value is used as an increment counter for the throttle count.
You can create a custom throttle monitor by defining a metric based on the request content of the message. The metric is defined by the following parameters -
The monitor for a throttle is defined in a transformation (XSLT) file. The XSLT file is configured as a parse XSLT file for an operation. When a request goes through the parsing step of the request operation, the Core Engine reads all the data from the XSLT file and creates the throttle monitors.
For example, you can define a throttle for a bookorder service that orders the books from a store. You can define the throttle in such a way that the service is not overloaded with the client requests.
A throttle T1_BookOrder is defined in such a way that the throttle T1_BookOrder allows a user to order only 20 books in 10 seconds. In such a case, a throttle T1_BookOrder is configured using the Config UI as follows:

 
Throttle Name: T1_BookOrder
Throttle Type: Rate
Throttle Interval: 10 seconds
Throttle Max Count: 20

 
For this scenario, the Core Engine allows a maximum of 20 requests within 10 seconds. You can extend the throttle policy by creating a monitor to allow a specific number of book orders in a single request.
For example, you can create a custom throttle monitor for this throttle T1_BookOrder to increment the throttle count based on the number of book orders in the request. This allows you to customize the throttle count by providing the increment counter defined as metricIncrement for the monitor. The metricIncrement for this monitor can be populated using an XPath formula based on the total number of book orders in the request message. In this case, you can define the metricIncrement to count the book orders in the request. So, if the count of book orders in a request is 5, then it increments the throttle count as 5 allowing only 4 similar requests within 10 seconds.
Configuring Content-Based Throttles
To configure the content based throttles, you need a XSLT file which typically contains an XPath formula. The XSLT file defines the metric definition to create the custom monitor. The Core Engine evaluates and parses the XSLT file in the parsing step for an operation in the request processing pipeline and creates the monitor based on the metric definition.
To configure the content-based throttle monitors, follow these steps:
Configure Throttle
Define the throttle in the Config UI to create a custom throttle monitor. To configure a throttle, follow these steps:
1.
2.
3.
4.
Click the MONITORS > Monitors tab.
5.
6.
Define XSLT File
Define an XSLT transformation file to configure a throttle monitor.
For example, the monitor for a throttle T1 is defined in the XSLT file using a <monitor> tag as follows:

 
<output>
<xsl:variable name="childnodes">
<xsl:value-of select="$nbRequest/loc:NewOrderReq/count(loc:OrderDtl)"/>
</xsl:variable>
<monitor>
<metricName>T1</metricName>
<metricIncrement><xsl:value-of select="$childnodes"/></metricIncrement>
</monitor>
</output>

 
In the preceding example, the metricIncrement is assigned based on the count of the OrderDtl element in the payload of an incoming request. If you have an input payload with n number of OrderDtl elements, you can parse the number of OrderDtl elements and assign that number to metricIncrement. The metricIncrement is applied to the throttle configuration.
If the XPath formula used in the metricIncrement field returns an invalid value, the content throttle increments the throttle count value by 1, which is the default value.
Example XML (Payload) Files
This section shows the sample XML files which shows payloads with 2 Orderdetails and 4 Orderdetails. Refer to Example XSLT File for the XSLT file for these payloads.

 
<?xml version = "1.0" encoding = "UTF-8"?>
<NewOrderReq xmlns = "http://www.tibco.com/schemas/TAO/NewOrderSchema-v3.xsd">
<CustID>11111</CustID>
<EmailID>user01@edusvr</EmailID>
<OrderDtl>
   <ProductID>1001</ProductID>
   <ProductDesc>Executive Black Leather Chair</ProductDesc>
   <Qty>1</Qty>
   <UnitPrice>159.99</UnitPrice>
</OrderDtl>
<OrderDtl>
   <ProductID>3002</ProductID>
   <ProductDesc>Medium point, black ink pens,50-pk</ProductDesc>
   <Qty>5</Qty>
   <UnitPrice>17.99</UnitPrice>
</OrderDtl>
<ShippingDtl>
<Address>3303 Hillview</Address>
<City>Palo Alto</City>
<State>CA</State>
<Zipcode>94303</Zipcode>
<Country>USA</Country>
</ShippingDtl>
</NewOrderReq>

 

 
<?xml version = "1.0" encoding = "UTF-8"?>
<NewOrderReq xmlns = "http://www.tibco.com/schemas/TAO/NewOrderSchema-v3.xsd">
<CustID>11111</CustID>
<EmailID>user01@edusvr</EmailID>
<OrderDtl>
   <ProductID>1001</ProductID>
   <ProductDesc>Executive Black Leather Chair</ProductDesc>
   <Qty>1</Qty>
   <UnitPrice>159.99</UnitPrice>
</OrderDtl>
<OrderDtl>
   <ProductID>3002</ProductID>
   <ProductDesc>Medium point, black ink pens,50-pk</ProductDesc>
   <Qty>5</Qty>
   <UnitPrice>17.99</UnitPrice>
</OrderDtl>
<OrderDtl>
   <ProductID>3002</ProductID>
   <ProductDesc>Medium point, black ink pens,50-pk</ProductDesc>
   <Qty>5</Qty>
   <UnitPrice>17.99</UnitPrice>
</OrderDtl>
<OrderDtl>
   <ProductID>3002</ProductID>
   <ProductDesc>Medium point, black ink pens,50-pk</ProductDesc>
   <Qty>5</Qty>
   <UnitPrice>17.99</UnitPrice>
</OrderDtl>
<ShippingDtl>
<Address>3303 Hillview</Address>
<City>Palo Alto</City>
<State>CA</State>
<Zipcode>94303</Zipcode>
<Country>USA</Country>
</ShippingDtl>
</NewOrderReq>

 
Example XSLT File
This section shows an example XSLT file which you can use as a reference to create an XSLT file. This XSLT file illustrates how you can use the number of OrderDtl element in a payload.

 
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:loc="http://www.tibco.com/schemas/TAO/NewOrderSchema-v3.xsd">
<xsl:template match="/">
<xsl:variable name="nbRequestHref">
<xsl:value-of select="/transformation/nbRequest/@href"/>
</xsl:variable>
<xsl:variable name="nbRequest">
<xsl:copy-of select="document($nbRequestHref)/soap:Envelope/soap:Body/*"/>
</xsl:variable>
<output>
<xsl:variable name="childnodes">
<xsl:value-of select="$nbRequest/loc:NewOrderReq/count(loc:OrderDtl)"/>
</xsl:variable>
<monitor>
<metricName>T1</metricName>
<metricIncrement><xsl:value-of select="$childnodes"/></metricIncrement>
</monitor>
</output>
</xsl:template>
</xsl:stylesheet>

 
Upload XSLT FIle
After you define the XSLT file for a throttle monitor, upload the file in the New ProcessBody XSLT field on facade Operations tab in the Config UI.
To upload the XSLT file, follow these steps:
1.
2.
3.
4.
Click the ROUTING tab on the right hand side.
5.
Click the Facade Operations tab on the top menu.
6.
7.
a.
Click the Choose File button in the New ProcessBody Transform field to select the monitor XSLT transformation file.
b.
Click Open button to upload the XSLT file.
8.

Copyright © Cloud Software Group, Inc. All Rights Reserved
Copyright © Cloud Software Group, Inc. All Rights Reserved