RoutePolicyAvailable as of Camel 2.1 A route policy org.apache.camel.spi.RoutePolicy is used to control route(s) at runtime. For example you can use it to determine whether a route should be running or not. However the policies can support any kind of use cases. How it worksYou associate a route with a given RoutePolicy and then during runtime Camel will invoke callbacks on this policy where you can implement your custom logic. Camel provides a support class that is a good base class to extend org.apache.camel.impl.RoutePolicySupport. There are these callbacks invoked
See the javadoc of the org.apache.camel.spi.RoutePolicy for more details. Camel provides the following policies out of the box:
As of Camel 2.5, Camel also provides an ability to schedule routes to be activated, de-activated, suspended and/or resumed at certain times during the day using a ScheduledRoutePolicy (offered via the camel-quartz component).
ThrottlingInflightRoutePolicyThe ThrottlingInflightRoutePolicy is triggered when an Exchange is complete, which means that it requires at least one Exchange to be complete before it works. The throttling inflight route policy has the following options:
ScheduledRoutePolicy (Simple and Cron based) using camel QuartzFor more details check out the following links Configuring policyYou configure the route policy as follows from Java DSL, using the routePolicy method: RoutePolicy myPolicy = new MyRoutePolicy(); from("seda:foo").routePolicy(myPolicy).to("mock:result"); In Spring XML its a bit different as follows using the routePolicyRef attribute: <bean id="myPolicy" class="com.mycompany.MyRoutePolicy"/> <route routePolicyRef="myPolicy"> <from uri="seda:foo"/> <to uri="mock:result"/> </route> Configuring policy setsAvailable as of Camel 2.7 RoutePolicy has been further improved to allow addition of policy sets or a collection of policies that are concurrently applied on a route. The addition of policies is done as follows. In the example below, the route testRoute has a startPolicy and throttlePolicy applied concurrently. Both policies are applied as necessary on the route. <bean id="date" class="org.apache.camel.routepolicy.quartz.SimpleDate"/> <bean id="startPolicy" class="org.apache.camel.routepolicy.quartz.SimpleScheduledRoutePolicy"> <property name="routeStartDate" ref="date"/> <property name="routeStartRepeatCount" value="1"/> <property name="routeStartRepeatInterval" value="3000"/> </bean> <bean id="throttlePolicy" class="org.apache.camel.impl.ThrottlingInflightRoutePolicy"> <property name="maxInflightExchanges" value="10"/> </bean> <camelContext id="testRouteContext" xmlns="http://camel.apache.org/schema/spring"> <route id="testRoute" autoStartup="false" routePolicyRef="startPolicy, throttlePolicy"> <from uri="seda:foo?concurrentConsumers=20"/> <to uri="mock:result"/> </route> </camelContext> </route> See Also
|