camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Camel > RoutePolicy
Date Mon, 02 Nov 2009 12:59:00 GMT
<html>
<head>
    <base href="http://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/1519/1/1/_/styles/combined.css?spaceKey=CAMEL&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background-color: white" bgcolor="white">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
     <h2><a href="http://cwiki.apache.org/confluence/display/CAMEL/RoutePolicy">RoutePolicy</a></h2>
     <h4>Page <b>edited</b> by             <a href="http://cwiki.apache.org/confluence/display/~davsclaus">Claus
Ibsen</a>
    </h4>
     
          <br/>
     <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>

<p>There are two callbacks invoked</p>
<ul class="alternate" type="square">
	<li><tt>onExchangeBegin</tt></li>
	<li><tt>onExchangeDone</tt></li>
</ul>


<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.ThrottlingRoutePolicy</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.ThrottlingRoutePolicy</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>
</ul>


<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
/><p>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>
instances.</p></td></tr></table></div>

<h4><a name="RoutePolicy-ThrottlingRoutePolicy"></a>ThrottlingRoutePolicy</h4>
<p>The throttling route policy has the following options:</p>

<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Option </th>
<th class='confluenceTh'> Default </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<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>
</tr>
<tr>
<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>
</tr>
<tr>
<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>
</tr>
<tr>
<td class='confluenceTd'> loggingLevel </td>
<td class='confluenceTd'> INFO </td>
<td class='confluenceTd'> The logging level used for logging the throttling activity.
</td>
</tr>
<tr>
<td class='confluenceTd'> logger </td>
<td class='confluenceTd'> ThrottlingRoutePolicy </td>
<td class='confluenceTd'> The logger category. </td>
</tr>
</tbody></table>

<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>
method:</p>
<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
class="code-quote">"mock:result"</span>);
</pre>
</div></div>

<p>In Spring XML its a bit different as follows using the <tt>routePolicyRef</tt>
attribute:</p>
<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>
</pre>
</div></div>

<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</li>
	<li><a href="/confluence/display/CAMEL/Architecture" title="Architecture">Architecture</a></li>
</ul>

     </div>
     <div id="commentsSection" class="wiki-content pageSection">
       <div style="float: right;">
            <a href="http://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
       </div>

       <a href="http://cwiki.apache.org/confluence/display/CAMEL/RoutePolicy">View Online</a>
       |
       <a href="http://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=5604260&revisedVersion=4&originalVersion=3">View
Change</a>
              |
       <a href="http://cwiki.apache.org/confluence/display/CAMEL/RoutePolicy?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message