camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Camel > Message Router
Date Thu, 14 Apr 2011 13:02: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/Message+Router">Message
Router</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~davsclaus">Claus
Ibsen</a>
    </h4>
        <br/>
                         <h4>Changes (2)</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" > <br>h4. Choice without otherwise
<br></td></tr>
            <tr><td class="diff-changed-lines" >If you use a {{choice}} without
adding an {{otherwise}}, any unmatched exchanges will be dropped by default. <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">
If you prefer to have an exception for an unmatched exchange, you can add a {{throwFault}}
to the {{otherwise}}.</span> <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">{code:java}
<br>  ....otherwise().throwFault(&quot;No matching when clause found on choice block&quot;);
<br>{code} <br></td></tr>
            <tr><td class="diff-unchanged" > <br>{include:Using This Pattern}
<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h3><a name="MessageRouter-MessageRouter"></a>Message Router</h3>

<p>The <a href="http://www.enterpriseintegrationpatterns.com/MessageRouter.html"
class="external-link" rel="nofollow">Message Router</a> from the <a href="/confluence/display/CAMEL/Enterprise+Integration+Patterns"
title="Enterprise Integration Patterns">EIP patterns</a> allows you to consume from
an input destination, evaluate some predicate then choose the right output destination.</p>

<p><span class="image-wrap" style=""><img src="http://www.enterpriseintegrationpatterns.com/img/MessageRouter.gif"
style="border: 0px solid black" /></span></p>

<p>The following example shows how to route a request from an input <b>queue:a</b>
endpoint to either <b>queue:b</b>, <b>queue:c</b> or <b>queue:d</b>
depending on the evaluation of various <a href="/confluence/display/CAMEL/Predicate" title="Predicate">Predicate</a>
expressions</p>

<p><b>Using the <a href="/confluence/display/CAMEL/Fluent+Builders" title="Fluent
Builders">Fluent Builders</a></b></p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">RouteBuilder builder = <span class="code-keyword">new</span>
RouteBuilder() {
    <span class="code-keyword">public</span> void configure() {
        errorHandler(deadLetterChannel(<span class="code-quote">"mock:error"</span>));

        from(<span class="code-quote">"seda:a"</span>)
            .choice()
                .when(header(<span class="code-quote">"foo"</span>).isEqualTo(<span
class="code-quote">"bar"</span>))
                    .to(<span class="code-quote">"seda:b"</span>)
                .when(header(<span class="code-quote">"foo"</span>).isEqualTo(<span
class="code-quote">"cheese"</span>))
                    .to(<span class="code-quote">"seda:c"</span>)
                .otherwise()
                    .to(<span class="code-quote">"seda:d"</span>);
    }
};
</pre>
</div></div>

<p><b>Using the <a href="/confluence/display/CAMEL/Spring+XML+Extensions" title="Spring
XML Extensions">Spring XML Extensions</a></b></p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml"><span class="code-tag">&lt;camelContext errorHandlerRef=<span
class="code-quote">"errorHandler"</span> xmlns=<span class="code-quote">"http://camel.apache.org/schema/spring"</span>&gt;</span>
    <span class="code-tag">&lt;route&gt;</span>
        <span class="code-tag">&lt;from uri=<span class="code-quote">"seda:a"</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>$foo = 'bar'<span
class="code-tag">&lt;/xpath&gt;</span>
                <span class="code-tag">&lt;to uri=<span class="code-quote">"seda:b"</span>/&gt;</span>
            <span class="code-tag">&lt;/when&gt;</span>
            <span class="code-tag">&lt;when&gt;</span>
                <span class="code-tag">&lt;xpath&gt;</span>$foo = 'cheese'<span
class="code-tag">&lt;/xpath&gt;</span>
                <span class="code-tag">&lt;to uri=<span class="code-quote">"seda:c"</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">"seda:d"</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>
<span class="code-tag">&lt;/camelContext&gt;</span>
</pre>
</div></div>

<h4><a name="MessageRouter-Choicewithoutotherwise"></a>Choice without otherwise</h4>
<p>If you use a <tt>choice</tt> without adding an <tt>otherwise</tt>,
any unmatched exchanges will be dropped by default. </p>

<h4><a name="MessageRouter-UsingThisPattern"></a>Using This Pattern</h4>

<p>If you would like to use this EIP Pattern then please read the <a href="/confluence/display/CAMEL/Getting+Started"
title="Getting Started">Getting Started</a>, you may also find the <a href="/confluence/display/CAMEL/Architecture"
title="Architecture">Architecture</a> useful particularly the description of <a
href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a> and <a
href="/confluence/display/CAMEL/URIs" title="URIs">URIs</a>. Then you could try out
some of the <a href="/confluence/display/CAMEL/Examples" title="Examples">Examples</a>
first before trying this pattern out.</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/Message+Router">View
Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=49441&revisedVersion=10&originalVersion=9">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/Message+Router?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message