camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Camel > Load Balance for existing Messaging Service
Date Wed, 29 Aug 2012 16:33:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/2042/9/1/_/styles/combined.css?spaceKey=CAMEL&amp;forWysiwyg=true"
type="text/css">
    </head>
<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="https://cwiki.apache.org/confluence/display/CAMEL/Load+Balance+for+existing+Messaging+Service">Load
Balance for existing Messaging Service</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~davsclaus">Claus
Ibsen</a>
    </h4>
        <br/>
                         <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" >{code} <br>from(&quot;file:src/data?noop=true&quot;).convertBodyTo(java.lang.String.class).to(&quot;stream:out&quot;)
<br></td></tr>
            <tr><td class="diff-unchanged" >  .loadBalance().random()
    .to(&quot;activemq:personnel.records1&quot;)
    .to(&quot;activemq:personnel.records2&quot;)
  .end() <br></td></tr>
            <tr><td class="diff-unchanged" >{code} <br>Let the route2 collect
messages from both queues providing the load balance support: <br>{code} <br>from(&quot;activemq:personnel.records1&quot;,
&quot;activemq:personnel.records2&quot;) <br></td></tr>
            <tr><td class="diff-unchanged" >  .choice()
    .when().xpath(&quot;/person/city = &#39;London&#39;&quot;).to(&quot;file:target/messages/uk&quot;)
    .otherwise().to(&quot;file:target/messages/others&quot;)
  .end() <br></td></tr>
            <tr><td class="diff-unchanged" >{code} <br> <br>With these
two operations, you have complete this work. Just throw your message into the directory, camel
will process and deliver it automatically. By the way, you may need some [Dead Letter Channel]
configuration for it since XML analyzing with rigid format usually accompanies frequent error.
<br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">
<br>h3. Source code <br> <br>If you would not like to build it by yourself,
a copy is here: <br>{attachments:patterns=.*Sample.zip} <br>Just extract it and
run it. <br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h2><a name="LoadBalanceforexistingMessagingService-LoadBalanceforExistingMessagingService"></a>Load
Balance for Existing Messaging Service</h2>

<p>This is a sample to show how we can change our existing messaging service for requirement
or improvement. Here we use a load balance support as example. </p>

<h3><a name="LoadBalanceforexistingMessagingService-Buildthesample"></a>Build
the sample</h3>

<p>Imagine that we have a message handling system built before to collect some information
from our client and then process and record them. This scenario can be constructed by using
the following XML route configuration.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;route&gt;</span>
  <span class="code-tag">&lt;from uri=<span class="code-quote">"file:src/data?noop=true"</span>/&gt;</span>
      
  <span class="code-tag"><span class="code-comment">&lt;!-- Print the message
to standard out, just as a test --&gt;</span></span>
  <span class="code-tag">&lt;convertBodyTo type=<span class="code-quote">"java.lang.String"</span>/&gt;</span>
  <span class="code-tag">&lt;to uri=<span class="code-quote">"stream:out"</span>/&gt;</span>

      
  <span class="code-tag">&lt;to uri=<span class="code-quote">"activemq:personnel.records"</span>/&gt;</span>
<span class="code-tag">&lt;/route&gt;</span>

<span class="code-tag">&lt;route&gt;</span>
  <span class="code-tag">&lt;from uri=<span class="code-quote">"activemq:personnel.records"</span>/&gt;</span>
  <span class="code-tag">&lt;choice&gt;</span>
     <span class="code-tag">&lt;when&gt;</span>
       <span class="code-tag">&lt;xpath&gt;</span>/person/city = 'London'<span
class="code-tag">&lt;/xpath&gt;</span>
       <span class="code-tag">&lt;to uri=<span class="code-quote">"file:target/messages/uk"</span>/&gt;</span>
     <span class="code-tag">&lt;/when&gt;</span>
     <span class="code-tag">&lt;otherwise&gt;</span>
       <span class="code-tag">&lt;to uri=<span class="code-quote">"file:target/messages/others"</span>/&gt;</span>
     <span class="code-tag">&lt;/otherwise&gt;</span>
  <span class="code-tag">&lt;/choice&gt;</span>
 <span class="code-tag">&lt;/route&gt;</span>
</pre>
</div></div>
<p>For more instruction to build your sample, read the <a href="/confluence/display/CAMEL/Camel+Maven+Archetypes"
title="Camel Maven Archetypes">Camel Maven Archetypes</a> page. The above routes
are the default configuration for your new sample, so you can get started with it easily.
<br/>
In this scenario, the first route is responsible to collect data from a directory: src/data,
print it to standard output console and deliver it to a message queue to further processing.
Then, another route get messages from the queue, and use <a href="/confluence/display/CAMEL/Content+Based+Router"
title="Content Based Router">Content Based Router</a> to sort out them. The messages
for person in London are stored in the directory: target/messages/uk, and others in target/messages/others.
You can run this sample using command:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
mvn jetty:run-war
</pre>
</div></div>
<p>After started, we can view the routes configured in camel context by directing your
browser to <a href="http://localhost:8080/routes" class="external-link" rel="nofollow">http://localhost:8080/routes</a>.<br/>
<span class="image-wrap" style="display: block; text-align: center"><img src="/confluence/download/attachments/2851422/route_list_page.jpg?version=1&amp;modificationDate=1250668556000"
style="border: 0px solid black" /></span><br/>
There are originally several message files in the directory: src/data and the message system
processes them once it is started. We can get the processing result by checking the console
and the files in target/messages.</p>

<h3><a name="LoadBalanceforexistingMessagingService-UseWebConsoletoaddloadbalancesupport"></a>Use
<a href="/confluence/display/CAMEL/Web+Console" title="Web Console">Web Console</a>
to add load balance support</h3>

<p>For a handful of small messages, one queue is enough to handle. But when encountering
high volumn message input, we may want to use several queues to provide a load balance mechanism.
So we can use the camel <a href="/confluence/display/CAMEL/Load+Balancer" title="Load Balancer">Load
Balancer</a> support. The messaging service improvement here is much easier than that
in other messaging system. You can open the routes on the above page.<br/>
<span class="image-wrap" style="display: block; text-align: center"><img src="/confluence/download/attachments/2851422/route_view_page.jpg?version=1&amp;modificationDate=1250668966000"
style="border: 0px solid black" /></span><br/>
Use a loadBalance DSL for the message delivery on route1:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"file:src/data?noop=<span class="code-keyword">true</span>"</span>).convertBodyTo(java.lang.<span
class="code-object">String</span>.class).to(<span class="code-quote">"stream:out"</span>)
  .loadBalance().random()
    .to(<span class="code-quote">"activemq:personnel.records1"</span>)
    .to(<span class="code-quote">"activemq:personnel.records2"</span>)
  .end()
</pre>
</div></div>
<p>Let the route2 collect messages from both queues providing the load balance support:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"activemq:personnel.records1"</span>, <span class="code-quote">"activemq:personnel.records2"</span>)
  .choice()
    .when().xpath(<span class="code-quote">"/person/city = 'London'"</span>).to(<span
class="code-quote">"file:target/messages/uk"</span>)
    .otherwise().to(<span class="code-quote">"file:target/messages/others"</span>)
  .end()
</pre>
</div></div>

<p>With these two operations, you have complete this work. Just throw your message into
the directory, camel will process and deliver it automatically. By the way, you may need some
<a href="/confluence/display/CAMEL/Dead+Letter+Channel" title="Dead Letter Channel">Dead
Letter Channel</a> configuration for it since XML analyzing with rigid format usually
accompanies frequent error.</p>

    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;">
            <a href="https://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
        </div>
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/Load+Balance+for+existing+Messaging+Service">View
Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=2851422&revisedVersion=9&originalVersion=8">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/Load+Balance+for+existing+Messaging+Service?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message