This site contains the documentation that is relevant to older WSO2 product versions and offerings.
For the latest WSO2 documentation, visit https://wso2.com/documentation/.
Throttle Mediator
The Throttle Mediator can be used for rate-limiting as well as concurrency-based limiting. A WS-Policy dictates the throttling configuration and may be specified inline or loaded from the registry. The Throttle Mediator could be added in the request path for rate limiting and concurrent access limitation. When using for concurrent access limitation, the same Throttle Mediator id
must be triggered on the response flow so that completed responses are deducted from the available limit. (i.e. two instances of the throttle mediator with the same id
attribute in the request and response flows). The onReject
and onAccept
sequence references or inline sequences define how accepted and rejected messages are to be handled.
The Throttle mediator carries out throttling for a proxy service at the stage where requests are being mediated. If you want the throttling to be carried out before mediation, define a throttle policy at service level.
Â
Syntax
<throttle [onReject="string"] [onAccept="string"] id="string"> (<policy key="string"/> | <policy>..</policy>) <onReject>..</onReject>? <onAccept>..</onAccept>? </throttle>
UI Configuration
Throttle Mediator Options:
Throttle Group ID -Â The id for the throttle group.
Note
You would have to throttle mediator configuration in request and response paths with the same group id.
- Throttle Referring Policy -Â The policy for the throttling. You can specify it inline or refer from Configuration Registry or Governance Registry.
- On Acceptance Referring Sequence -Â The sequence to act on acceptance. You can specify it inline or refer from Configuration Registry or Governance Registry.
- On Rejection Referring Sequence -Â The sequence to act on rejection. You can specify it inline or refer from Configuration Registry or Governance Registry.
For more information on the registry, see Working with the Registry.
Note
You can configure the Mediator using XML. Click on "switch to source view" in the "Mediator" window.
Example
<in> <throttle id="A"> <policy> <!-- define throttle policy --> <wsp:Policy xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:throttle="http://www.wso2.org/products/wso2commons/throttle"> <throttle:ThrottleAssertion> <throttle:MaximumConcurrentAccess>10</throttle:MaximumConcurrentAccess> </throttle:ThrottleAssertion> </wsp:Policy> </policy> <onAccept> <log level="custom"> <property name="text" value="**Access Accept**"/> </log> <send> <endpoint> <address uri="http://localhost:9000/services/SimpleStockQuoteService"/> </endpoint> </send> </onAccept> <onReject> <log level="custom"> <property name="text" value="**Access Denied**"/> </log> <makefault> <code value="tns:Receiver" xmlns:tns="http://www.w3.org/2003/05/soap-envelope"/> <reason value="**Access Denied**"/> </makefault> <property name="RESPONSE" value="true"/> <header name="To" action="remove"/> <send/> <drop/> </onReject> </throttle> </in>
The above example specifies the Throttle Mediator inside the In Mediator. Therefore, all request messages directed to the main sequence will be subjected to throttling. The Throttle Mediator has policy
, onAccept
and onReject
tags at top level. The policy
tag specifies the throttling policy for throttling messages. This sample policy only contains a component called MaximumConcurrentAccess
. This indicates the maximum number of concurrent requests that can pass through Synapse on a single unit of time.