Objective: Use of both concurrency throttling and request rate based throttling.
<!-- Use of both concurrency throttling and request rate based throttling --> <definitions xmlns="http://ws.apache.org/ns/synapse"> <registry provider="org.wso2.carbon.mediation.registry.ESBRegistry"> <!-- the root property of the simple URL registry helps resolve a resource URL as root + key --> <parameter name="root">file:repository/</parameter> <!-- all resources loaded from the URL registry would be cached for this number of milli seconds --> <parameter name="cachableDuration">150000</parameter> </registry> <sequence name="onAcceptSequence"> <log level="custom"> <property name="text" value="**Access Accept**"/> </log> <send> <endpoint> <address uri="http://localhost:9000/services/SimpleStockQuoteService"/> </endpoint> </send> </sequence> <sequence name="onRejectSequence" trace="enable"> <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/> </sequence> <proxy name="StockQuoteProxy"> <target> <inSequence> <throttle onReject="onRejectSequence" onAccept="onAcceptSequence" id="A"> <policy key="repository/samples/resources/policy/throttle_policy.xml"/> </throttle> </inSequence> <outSequence> <throttle id="A"/> <send/> </outSequence> </target> <publishWSDL uri="file:repository/samples/resources/proxy/sample_proxy_1.wsdl"/> </proxy> </definitions>
- Deploy the SimpleStockQuoteService in sample Axis2 server and start it on port 9000.
- Create the above configuration and deploy it in the WSO2 EI profile, see Working with WSO2 Integration Studio.
Throttle policy is loaded from the ?throttle_policy.xml? .That policy contains merging policy from sample 370 and 371. To check the functionality , it is need to run load test. The all-enabled request from the concurrency throttling will be controlled by the access rate base throttling according to the policy.
Run the client as follows:
ant stockquote -Daddurl=http://localhost:8280/services/StockQuoteProxy
You will get results same as sample 371.if you run the load test, results will be different due to affect of concurrency throttling.
Extending the mediation in java (Class Mediator)
Class mediator can be used to write your own custom mediation in Java and you have access to the SynapseMessageContext and to the full Synapse API in there. This is a useful extension mechanism within ESB to extend its functionality. This class can contain fields for which you can assign values at runtime through the configuration.