camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Camel > Multicast
Date Tue, 15 Feb 2011 15:42:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/2036/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/Multicast">Multicast</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~tmielke">Torsten
Mielke</a>
    </h4>
        <div id="versionComment">
        <b>Comment:</b>
        Note added that default is sequential processing and that AggregationStrategy is used
to gather replies.<br />
    </div>
        <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" >{snippet:id=example|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/MulticastTest.java}
<br> <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">By
default Multicast invokes each endpoint sequentially. If parallel processing is desired, simply
use <br>{code} <br>from(&quot;direct:a&quot;).multicast().parallelProcessing().to(&quot;direct:x&quot;,
&quot;direct:y&quot;, &quot;direct:z&quot;); <br>{code} <br> <br>In
case of using InOut MEP, an AggregationStrategy is used for aggregating all reply messages.
The default is to only use the latest reply message and discard any earlier replies. The aggregation
strategy is configurable: <br> <br>{code} <br>from(&quot;direct:start&quot;)
<br>  .multicast(new MyAggregationStrategy()) <br>  .parallelProcessing().timeout(500).to(&quot;direct:a&quot;,
&quot;direct:b&quot;, &quot;direct:c&quot;) <br>  .end() <br>
 .to(&quot;mock:result&quot;); <br>{code} <br> <br> <br></td></tr>
            <tr><td class="diff-unchanged" >h3. Stop processing in case of exception
<br>*Available as of Camel 2.1* <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h3><a name="Multicast-Multicast"></a>Multicast</h3>
<p>The Multicast allows to route the same message to a number of endpoints and process
them in a different way. The main difference between the Multicast and Splitter is that Splitter
will split the message into several pieces but the Multicast will not modify the request message.</p>


<h4><a name="Multicast-Example"></a>Example</h4>

<p>The following example shows how to take a request from the <b>direct:a</b>
endpoint , then multicast these request to <b>direct:x</b>, <b>direct:y</b>,
<b>direct:z</b>.</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">from(<span class="code-quote">"direct:a"</span>).multicast().to(<span
class="code-quote">"direct:x"</span>, <span class="code-quote">"direct:y"</span>,
<span class="code-quote">"direct:z"</span>);
</pre>
</div></div>

<p>By default Multicast invokes each endpoint sequentially. If parallel processing is
desired, simply use</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"direct:a"</span>).multicast().parallelProcessing().to(<span
class="code-quote">"direct:x"</span>, <span class="code-quote">"direct:y"</span>,
<span class="code-quote">"direct:z"</span>);
</pre>
</div></div>

<p>In case of using InOut MEP, an AggregationStrategy is used for aggregating all reply
messages. The default is to only use the latest reply message and discard any earlier replies.
The aggregation strategy is configurable:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"direct:start"</span>)
  .multicast(<span class="code-keyword">new</span> MyAggregationStrategy())
  .parallelProcessing().timeout(500).to(<span class="code-quote">"direct:a"</span>,
<span class="code-quote">"direct:b"</span>, <span class="code-quote">"direct:c"</span>)
  .end()
  .to(<span class="code-quote">"mock:result"</span>);
</pre>
</div></div>


<h3><a name="Multicast-Stopprocessingincaseofexception"></a>Stop processing
in case of exception</h3>
<p><b>Available as of Camel 2.1</b></p>

<p>The <a href="/confluence/display/CAMEL/Multicast" title="Multicast">Multicast</a>
will by default continue to process the entire <a href="/confluence/display/CAMEL/Exchange"
title="Exchange">Exchange</a> even in case one of the multicasted messages will thrown
an exception during routing.<br/>
For example if you want to multicast to 3 destinations and the 2nd destination fails by an
exception. What Camel does by default is to process the remainder destinations. You have the
chance to remedy or handle this in the <tt>AggregationStrategy</tt>.</p>

<p>But sometimes you just want Camel to stop and let the exception be propagated back,
and let the Camel error handler handle it. You can do this in Camel 2.1 by specifying that
it should stop in case of an exception occurred. This is done by the <tt>stopOnException</tt>
option as shown below:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
    from(<span class="code-quote">"direct:start"</span>)
        .multicast()
            .stopOnException().to(<span class="code-quote">"direct:foo"</span>,
<span class="code-quote">"direct:bar"</span>, <span class="code-quote">"direct:baz"</span>)
        .end()
        .to(<span class="code-quote">"mock:result"</span>);

        from(<span class="code-quote">"direct:foo"</span>).to(<span class="code-quote">"mock:foo"</span>);

        from(<span class="code-quote">"direct:bar"</span>).process(<span class="code-keyword">new</span>
MyProcessor()).to(<span class="code-quote">"mock:bar"</span>);

        from(<span class="code-quote">"direct:baz"</span>).to(<span class="code-quote">"mock:baz"</span>);
</pre>
</div></div>

<p>And using XML DSL you specify it as follows:</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">"direct:start"</span>/&gt;</span>
            <span class="code-tag">&lt;multicast stopOnException=<span class="code-quote">"true"</span>&gt;</span>
                <span class="code-tag">&lt;to uri=<span class="code-quote">"direct:foo"</span>/&gt;</span>
                <span class="code-tag">&lt;to uri=<span class="code-quote">"direct:bar"</span>/&gt;</span>
                <span class="code-tag">&lt;to uri=<span class="code-quote">"direct:baz"</span>/&gt;</span>
            <span class="code-tag">&lt;/multicast&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>

        <span class="code-tag">&lt;route&gt;</span>
            <span class="code-tag">&lt;from uri=<span class="code-quote">"direct:foo"</span>/&gt;</span>
            <span class="code-tag">&lt;to uri=<span class="code-quote">"mock:foo"</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">"direct:bar"</span>/&gt;</span>
            <span class="code-tag">&lt;process ref=<span class="code-quote">"myProcessor"</span>/&gt;</span>
            <span class="code-tag">&lt;to uri=<span class="code-quote">"mock:bar"</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">"direct:baz"</span>/&gt;</span>
            <span class="code-tag">&lt;to uri=<span class="code-quote">"mock:baz"</span>/&gt;</span>
        <span class="code-tag">&lt;/route&gt;</span>
</pre>
</div></div>

<h4><a name="Multicast-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/Multicast">View Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=81611&revisedVersion=8&originalVersion=7">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/Multicast?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message