camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject [CONF] Apache Camel > RoutePolicy
Date Thu, 30 Sep 2010 17:17:00 GMT
    <base href="">
            <link rel="stylesheet" href="/confluence/s/1810/9/1/_/styles/combined.css?spaceKey=CAMEL&amp;forWysiwyg=true"
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="">RoutePolicy</a></h2>
    <h4>Page <b>edited</b> by             <a href="">Ashwin
                         <h4>Changes (1)</h4>
<div id="page-diffs">
            <table class="diff" cellpadding="0" cellspacing="0">
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >h3. See Also <br>- [Route Throttling
Example] for an example using this in practice with the ThrottlingInflightRoutePolicy <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">-
[ScheduledRoutePolicy] for information on policy based scheduling capability for camel routes
            <tr><td class="diff-unchanged" >- [Architecture] <br></td></tr>
</div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h2><a name="RoutePolicy-RoutePolicy"></a>RoutePolicy</h2>
<p><b>Available as of Camel 2.1</b></p>

<p>A route policy <tt>org.apache.camel.spi.RoutePolicy</tt> 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 is can support any kind of use cases.</p>

<h3><a name="RoutePolicy-Howitworks"></a>How it works</h3>
<p>You associate a route with a given <tt>RoutePolicy</tt> and then during
runtime Camel will invoke callbacks on this policy where you can implement your custom logic.</p>

<p>Camel provides a support class that is a good base class to extend <tt>org.apache.camel.impl.RoutePolicySupport</tt>.

<p>There are these callbacks invoked</p>
<ul class="alternate" type="square">
	<li><tt>onInit</tt> <b>Camel 2.3</b></li>

<p>See the javadoc of the <tt>org.apache.camel.spi.RoutePolicy</tt> for
more details.<br/>
And also the implementation of the <tt>org.apache.camel.impl.ThrottlingInflightRoutePolicy</tt>
for a concrete example.</p>

<p>Camel provides the following policies out of the box:</p>
<ul class="alternate" type="square">
	<li><tt>org.apache.camel.impl.ThrottlingInflightRoutePolicy</tt> - a throttling
based policy that automatic suspends/resumes route(s) based on metrics from the current in
flight exchanges. You can use this to dynamic throttle e.g. a <a href="/confluence/display/CAMEL/JMS"
title="JMS">JMS</a> consumer to avoid it consuming too fast.</li>

<p>As of <b>Camel 2.5</b>, 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 <a href="/confluence/display/CAMEL/ScheduledRoutePolicy" title="ScheduledRoutePolicy">ScheduledRoutePolicy</a>
(offered via the <a href="" class="external-link" rel="nofollow">camel-quartz</a>
component). </p>

<div class='panelMacro'><table class='tipMacro'><colgroup><col width='24'><col></colgroup><tr><td
valign='top'><img src="/confluence/images/icons/emoticons/check.gif" width="16" height="16"
align="absmiddle" alt="" border="0"></td><td><b>SuspendableService</b><br
/>If you want to dynamic suspend/resume routes as the <tt>org.apache.camel.impl.ThrottlingRoutePolicy</tt>
does then its advised to use <tt>org.apache.camel.SuspendableService</tt> as it
allows for fine grained <tt>suspend</tt> and <tt>resume</tt> operations.
And use the <tt>org.apache.camel.util.ServiceHelper</tt> to aid when invoking
these operations as it support fallback for regular <tt>org.apache.camel.Service</tt>

<h4><a name="RoutePolicy-ThrottlingInflightRoutePolicy"></a>ThrottlingInflightRoutePolicy</h4>
<p>The ThrottlingInflightRoutePolicy is triggered when an <a href="/confluence/display/CAMEL/Exchange"
title="Exchange">Exchange</a> is complete, which means that it requires at least
one <a href="/confluence/display/CAMEL/Exchange" title="Exchange">Exchange</a>
to be complete before it <em>works</em>. </p>

<p>The throttling inflight route policy has the following options:</p>

<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<th class='confluenceTh'> Option </th>
<th class='confluenceTh'> Default </th>
<th class='confluenceTh'> Description </th>
<td class='confluenceTd'> scope </td>
<td class='confluenceTd'> Route </td>
<td class='confluenceTd'> A scope for either <tt>Route</tt> or <tt>Context</tt>
which defines if the current number of inflight exchanges is context based or for that particular
route. </td>
<td class='confluenceTd'> maxInflightExchanges </td>
<td class='confluenceTd'> 1000 </td>
<td class='confluenceTd'> The maximum threshold when the throttling will start to suspend
the route if the current number of inlfight exchanges is higher than this value. </td>
<td class='confluenceTd'> resumePercentOfMax </td>
<td class='confluenceTd'> 70 </td>
<td class='confluenceTd'> A percentage 0..100 which defines when the throttling should
resume again in case it has been suspended. </td>
<td class='confluenceTd'> loggingLevel </td>
<td class='confluenceTd'> INFO </td>
<td class='confluenceTd'> The logging level used for logging the throttling activity.
<td class='confluenceTd'> logger </td>
<td class='confluenceTd'> ThrottlingInflightRoutePolicy </td>
<td class='confluenceTd'> The logger category. </td>

<h4><a name="RoutePolicy-ScheduledRoutePolicy%28SimpleandCronbased%29usingcamelQuartz"></a>ScheduledRoutePolicy
(Simple and Cron based) using camel Quartz</h4>

<p>For more details check out the following links</p>

<div class='panelMacro'><table class='infoMacro'><colgroup><col width='24'><col></colgroup><tr><td
valign='top'><img src="/confluence/images/icons/emoticons/information.gif" width="16"
height="16" align="absmiddle" alt="" border="0"></td><td><b>ThrottlingInflightRoutePolicy
compared to the <a href="/confluence/display/CAMEL/Throttler" title="Throttler">Throttler</a>
EIP</b><br />The <tt>ThrottlingInflightRoutePolicy</tt> compared to
<a href="/confluence/display/CAMEL/Throttler" title="Throttler">Throttler</a>
is that it does <b>not</b> block during throttling. It does throttling that is
approximate based, meaning that its more coarse grained and not explicit precise as the <a
href="/confluence/display/CAMEL/Throttler" title="Throttler">Throttler</a>. The <a
href="/confluence/display/CAMEL/Throttler" title="Throttler">Throttler</a> can be
much more accurate and only allow a specific number of messages being passed per a given time
unit. Also the <tt>ThrottlingInflightRoutePolicy</tt> is based its metrics on
number of inflight exchanges where as <a href="/confluence/display/CAMEL/Throttler" title="Throttler">Throttler</a>
is based on number of messages per time unit.</td></tr></table></div>

<h3><a name="RoutePolicy-Configuringpolicy"></a>Configuring policy</h3>

<p>You configure the route policy as follows from Java DSL, using the <tt>routePolicy</tt>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
  RoutePolicy myPolicy = <span class="code-keyword">new</span> MyRoutePolicy();
  from(<span class="code-quote">"seda:foo"</span>).routePolicy(myPolicy).to(<span

<p>In Spring XML its a bit different as follows using the <tt>routePolicyRef</tt>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
   <span class="code-tag">&lt;bean id=<span class="code-quote">"myPolicy"</span>
class=<span class="code-quote">"com.mycompany.MyRoutePolicy"</span>/&gt;</span>
   <span class="code-tag">&lt;route outePolicyRef=<span class="code-quote">"myPolicy"</span>&gt;</span>
       <span class="code-tag">&lt;from uri=<span class="code-quote">"seda:foo"</span>/&gt;</span>
       <span class="code-tag">&lt;to uri=<span class="code-quote">"mock:result"</span>/&gt;</span>
   <span class="code-tag">&lt;/route&gt;</span>

<h3><a name="RoutePolicy-SeeAlso"></a>See Also</h3>
<ul class="alternate" type="square">
	<li><a href="/confluence/display/CAMEL/Route+Throttling+Example" title="Route Throttling
Example">Route Throttling Example</a> for an example using this in practice with
the ThrottlingInflightRoutePolicy</li>
	<li><a href="/confluence/display/CAMEL/ScheduledRoutePolicy" title="ScheduledRoutePolicy">ScheduledRoutePolicy</a>
for information on policy based scheduling capability for camel routes</li>
	<li><a href="/confluence/display/CAMEL/Architecture" title="Architecture">Architecture</a></li>

        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;">
            <a href=""
class="grey">Change Notification Preferences</a>
        <a href="">View
        <a href="">View
        <a href=";showCommentArea=true#addcomment">Add

View raw message