Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

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.

...

Table of Contents
maxLevel3
minLevel3
locationtop
styleborder:1
typeflat
separatorpipe

...

Syntax

Code Block
XML
XML
<throttle [onReject="string"] [onAccept="string"] id="string">
    (<policy key="string"/> | <policy>..</policy>)
    <onReject>..</onReject>?
    <onAccept>..</onAccept>?
</throttle>

...

  • Throttle Group ID - The id for the throttle group.
    Info
    titleNote

    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.

See Refer to more information about the Registry Browser in Namespace.

Info
titleNote

You can configure the Mediator using XML. Click on "switch to source view" in the "Mediator" window.

...

Example

Code Block
XML
XML
<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 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.

...