Route Throttling ExamplePage edited by Claus IbsenRoute Throttling ExampleAvailable as of Camel 2.1 AboutThis example shows how to use the new feature RoutePolicy to dynamically at runtime to throttle routes based on metrics gathered by the current number of inflight exchanges. What it means is that Camel will dynamic throttle the routes based on the flow of messages being processed at runtime. The example have 3 routes where as two of the routes are input routes, and the last is the processing route How it worksWhen the example runs we have a dependency from the routes as follows:
What the example demonstrates is that Camel is capable of dynamic throttling route1 and route2 based on the total flow of messages. At runtime Camel gathers the current inflight exchanges in a registry which is used for metrics. So when the flow is going too fast then the RoutePolicy kicks in and suspends route1 and/or route2. The current inflight exchanges will continue to be processed and when we are below a threshold then the RoutePolicy kicks in again and resumes route1 and/or route2. Camel provides the throttling policy in the org.apache.camel.impl.ThrottlingRoutePolicy. How to runThe example has 3 maven goals to run the example mvn compile exec:java -PCamelServer - starts the Camel Server which contains the 3 routes and where you should check its log output for how it goes. mvn compile exec:java -PCamelClient - is a client that sends 10000 JMS messages to the JMS broker which is consumed by route1. The Server must be started beforehand. mvn compile exec:java -PCamelFileClient - is a client that creates 5000 files that are consumed by route2. The server may be started beforehand, but its not required. So at first you start the server. Then at any time you can run a client at will. For example you can run the JMS client and let it run to completion at the server. You can see at the server console logging that it reports the progress. And at sometime it will reach 10000 messages processed. You can then start the client again if you like. You can also start the other client to create the files which then let the example be a bit more complicated as we have concurrent processing of JMS messages and files at the same time. And where as both of these should be dynamic throttled so we wont go too fast. How to changeYou can check the file src/main/resources/META-INF/spring/camel-server.xml file where you can see the configuration of the dynamic throttler. By default its configured as: <bean id="myPolicy" class="org.apache.camel.impl.ThrottlingRoutePolicy"> <!-- define the scope to be context scoped so we measure against total inflight exchanges that means for both route1, route2 and route3 all together --> <property name="scope" value="Context"/> <!-- when we hit > 30 inflight exchanges then kick in and suspend the routes --> <property name="maxInflightExchanges" value="30"/> <!-- when we hit lower than 10% of the max = 3 then kick in and resume the routes the default percentage is 70% but in this demo we want a low value --> <property name="resumePercentOfMax" value="10"/> <!-- output throttling activity at WARN level --> <property name="loggingLevel" value="WARN"/> </bean>
Change Notification Preferences
View Online
|
View Change
|
Add Comment
|
- [CONF] Apache Camel > Route Throttling Example confluence
- [CONF] Apache Camel > Route Throttling Example confluence
- [CONF] Apache Camel > Route Throttling Example confluence
- [CONF] Apache Camel > Route Throttling Example confluence
- [CONF] Apache Camel > Route Throttling Example confluence
