Modified: websites/production/camel/content/leveldb.html
==============================================================================
--- websites/production/camel/content/leveldb.html (original)
+++ websites/production/camel/content/leveldb.html Fri Aug 25 09:20:43 2017
@@ -36,17 +36,6 @@
<![endif]-->
- <link href='//camel.apache.org/styles/highlighter/styles/shCoreCamel.css'
rel='stylesheet' type='text/css' />
- <link href='//camel.apache.org/styles/highlighter/styles/shThemeCamel.css'
rel='stylesheet' type='text/css' />
- <script src='//camel.apache.org/styles/highlighter/scripts/shCore.js'
type='text/javascript'></script>
- <script src='//camel.apache.org/styles/highlighter/scripts/shBrushJava.js'
type='text/javascript'></script>
- <script src='//camel.apache.org/styles/highlighter/scripts/shBrushXml.js'
type='text/javascript'></script>
- <script src='//camel.apache.org/styles/highlighter/scripts/shBrushPlain.js'
type='text/javascript'></script>
-
- <script type="text/javascript">
- SyntaxHighlighter.defaults['toolbar'] = false;
- SyntaxHighlighter.all();
- </script>
<title>
Apache Camel: LevelDB
@@ -86,59 +75,12 @@
<tbody>
<tr>
<td valign="top" width="100%">
-<div class="wiki-content maincontent"><h2
id="LevelDB-LevelDB">LevelDB</h2><p><strong>Available as of Camel
2.10</strong></p><p><a shape="rect" class="external-link"
href="https://code.google.com/p/leveldb/" rel="nofollow">Leveldb</a> is a very
lightweight and embedable key value database. It allows together with Camel to
provide persistent support for various Camel features such as <a shape="rect"
href="aggregator2.html">Aggregator</a>.</p><p>Current features it
provides:</p><ul
class="alternate"><li>LevelDBAggregationRepository</li></ul><h3
id="LevelDB-UsingLevelDBAggregationRepository">Using
LevelDBAggregationRepository</h3><p><code>LevelDBAggregationRepository</code>
is an <code>AggregationRepository</code> which on the fly persists the
aggregated messages. This ensures that you will not loose messages, as the
default aggregator will use an in memory only
<code>AggregationRepository</code>.</p><p>It has the following options:</p><div
class="table-wrap"><table class="confluenceTa
ble"><tbody><tr><th colspan="1" rowspan="1"
class="confluenceTh"><p>Option</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Type</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Description</p></th></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>repositoryName</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>String</p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>A mandatory repository name. Allows you to
use a shared <code>LevelDBFile</code> for multiple
repositories.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>persistentFileName</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>String</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>Filename for the persistent storage. If no file exists
on startup a new file is created.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>levelDBFile</code></p></td><td colspan="1"
rowspan="1" class=
"confluenceTd"><p>LevelDBFile</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>Use an existing configured
<code>org.apache.camel.component.leveldb.LevelDBFile</code>
instance.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>sync</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>boolean</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><strong>Camel 2.12:</strong> Whether or not the
LevelDBFile should sync on write or not. Default is false. By sync on write
ensures that its always waiting for all writes to be spooled to disk and thus
will not loose updates. See <a shape="rect" class="external-link"
href="http://leveldb.googlecode.com/svn/trunk/doc/index.html"
rel="nofollow">LevelDB docs</a> for more details about async vs sync
writes.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>returnOldExchange</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>boolean</p></td><td colspan=
"1" rowspan="1" class="confluenceTd"><p>Whether the get operation should
return the old existing Exchange if any existed. By default this option is
<code>false</code> to optimize as we do not need the old exchange when
aggregating.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>useRecovery</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>boolean</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>Whether or not recovery is enabled. This option is by
default <code>true</code>. When enabled the Camel <a shape="rect"
href="aggregator2.html">Aggregator</a> automatic recover failed aggregated
exchange and have them resubmitted.</p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>recoveryInterval</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>long</p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>If recovery is enabled then a background
task is run every x'th time to scan for failed
exchanges to recover and resubmit. By default this interval is 5000
millis.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>maximumRedeliveries</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>int</p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Allows you to limit the maximum number of
redelivery attempts for a recovered exchange. If enabled then the Exchange will
be moved to the dead letter channel if all redelivery attempts failed. By
default this option is disabled. If this option is used then the
<code>deadLetterUri</code> option must also be provided.</p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>deadLetterUri</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>String</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>An endpoint uri for a <a shape="rect"
href="dead-letter-channel.html">Dead Letter Channel</a> where exhausted
recovered Exchanges will be moved. If this o
ption is used then the <code>maximumRedeliveries</code> option must also be
provided.</p></td></tr></tbody></table></div><p>The <code>repositoryName</code>
option must be provided. Then either the <code>persistentFileName</code> or the
<code>levelDBFile</code> must be provided.</p><h3
id="LevelDB-Whatispreservedwhenpersisting">What is preserved when
persisting</h3><p><code>LevelDBAggregationRepository</code> will only preserve
any <code>Serializable</code> compatible message body data types. Message
headers must be primitive / string / numbers / etc. If a data type is not such
a type its dropped and a <code>WARN</code> is logged. And it only persists the
<code>Message</code> body and the <code>Message</code> headers. The
<code>Exchange</code> properties are <strong>not</strong> persisted.</p><h3
id="LevelDB-Recovery">Recovery</h3><p>The
<code>LevelDBAggregationRepository</code> will by default recover any failed <a
shape="rect" href="exchange.html">Exchange</a>. It does this by havi
ng a background tasks that scans for failed <a shape="rect"
href="exchange.html">Exchange</a>s in the persistent store. You can use the
<code>checkInterval</code> option to set how often this task runs. The recovery
works as transactional which ensures that Camel will try to recover and
redeliver the failed <a shape="rect" href="exchange.html">Exchange</a>. Any <a
shape="rect" href="exchange.html">Exchange</a> which was found to be recovered
will be restored from the persistent store and resubmitted and send out
again.</p><p>The following headers is set when an <a shape="rect"
href="exchange.html">Exchange</a> is being recovered/redelivered:</p><div
class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1"
rowspan="1" class="confluenceTh"><p>Header</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Type</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Description</p></th></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>Exchang
e.REDELIVERED</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>Boolean</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>Is set to true to indicate the <a shape="rect"
href="exchange.html">Exchange</a> is being redelivered.</p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>Exchange.REDELIVERY_COUNTER</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>Integer</p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>The redelivery attempt, starting from
1.</p></td></tr></tbody></table></div><p>Only when an <a shape="rect"
href="exchange.html">Exchange</a> has been successfully processed it will be
marked as complete which happens when the <code>confirm</code> method is
invoked on the <code>AggregationRepository</code>. This means if the same <a
shape="rect" href="exchange.html">Exchange</a> fails again it will be kept
retried until it success.</p><p>You can use option
<code>maximumRedeliveries</code> to limit the
maximum number of redelivery attempts for a given recovered <a shape="rect"
href="exchange.html">Exchange</a>. You must also set the
<code>deadLetterUri</code> option so Camel knows where to send the <a
shape="rect" href="exchange.html">Exchange</a> when the
<code>maximumRedeliveries</code> was hit.</p><p>You can see some examples in
the unit tests of camel-leveldb, for example <a shape="rect"
class="external-link"
href="https://svn.apache.org/repos/asf/camel/trunk/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/LevelDBAggregateRecoverTest.java">this
test</a>.</p><h4 id="LevelDB-UsingLevelDBAggregationRepositoryinJavaDSL">Using
LevelDBAggregationRepository in Java DSL</h4><p>In this example we want to
persist aggregated messages in the <code>target/data/leveldb.dat</code>
file.</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
-public void configure() throws Exception {
- // create the leveldb repo
- LevelDBAggregationRepository repo = new
LevelDBAggregationRepository("repo1",
"target/data/leveldb.dat");
-
- // here is the Camel route where we aggregate
- from("direct:start")
- .aggregate(header("id"), new MyAggregationStrategy())
- // use our created leveldb repo as aggregation repository
- .completionSize(5).aggregationRepository(repo)
- .to("mock:aggregated");
-}
-]]></script>
-</div></div><h4
id="LevelDB-UsingLevelDBAggregationRepositoryinSpringXML">Using
LevelDBAggregationRepository in Spring XML</h4><p>The same example but using
Spring XML instead:</p><div class="code panel pdl" style="border-width:
1px;"><div class="codeContent panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
-
-<!-- a persistent aggregation repository using camel-leveldb -->
-<bean id="repo"
class="org.apache.camel.component.leveldb.LevelDBAggregationRepository">
- <!-- store the repo in the leveldb.dat file -->
- <property name="persistentFileName"
value="target/data/leveldb.dat"/>
- <!-- and use repo2 as the repository name -->
- <property name="repositoryName" value="repo2"/>
-</bean>
-
-<!-- aggregate the messages using this strategy -->
-<bean id="myAggregatorStrategy"
class="org.apache.camel.component.leveldb.LevelDBSpringAggregateTest$MyAggregationStrategy"/>
-
-<!-- this is the camel routes -->
-<camelContext id="camel"
xmlns="http://camel.apache.org/schema/spring">
-
- <route>
- <from uri="direct:start"/>
- <!-- aggregate using our strategy and leveldb repo, and complete
when we have 5 messages aggregated -->
- <aggregate strategyRef="myAggregatorStrategy"
aggregationRepositoryRef="repo" completionSize="5">
- <!-- correlate by header with the key id -->
-
<correlationExpression><header>id</header></correlationExpression>
- <!-- send aggregated messages to the mock endpoint -->
- <to uri="mock:aggregated"/>
- </aggregate>
- </route>
-
-</camelContext>
-]]></script>
-</div></div><h3 id="LevelDB-Dependencies">Dependencies</h3><p>To use <a
shape="rect" href="leveldb.html">LevelDB</a> in your camel routes you need to
add the a dependency on <strong>camel-leveldb</strong>.</p><p>If you use maven
you could just add the following to your pom.xml, substituting the version
number for the latest & greatest release (see <a shape="rect"
href="download.html">the download page for the latest versions</a>).</p><div
class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[<dependency>
+<div class="wiki-content maincontent"><h2
id="LevelDB-LevelDB">LevelDB</h2><p><strong>Available as of Camel
2.10</strong></p><p><a shape="rect" class="external-link"
href="https://code.google.com/p/leveldb/" rel="nofollow">Leveldb</a> is a very
lightweight and embedable key value database. It allows together with Camel to
provide persistent support for various Camel features such as <a shape="rect"
href="aggregator2.html">Aggregator</a>.</p><p>Current features it
provides:</p><ul
class="alternate"><li>LevelDBAggregationRepository</li></ul><h3
id="LevelDB-UsingLevelDBAggregationRepository">Using
LevelDBAggregationRepository</h3><p><code>LevelDBAggregationRepository</code>
is an <code>AggregationRepository</code> which on the fly persists the
aggregated messages. This ensures that you will not loose messages, as the
default aggregator will use an in memory only
<code>AggregationRepository</code>.</p><p>It has the following options:</p><div
class="table-wrap"><table class="confluenceTa
ble"><tbody><tr><th colspan="1" rowspan="1"
class="confluenceTh"><p>Option</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Type</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Description</p></th></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>repositoryName</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>String</p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>A mandatory repository name. Allows you to
use a shared <code>LevelDBFile</code> for multiple
repositories.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>persistentFileName</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>String</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>Filename for the persistent storage. If no file exists
on startup a new file is created.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>levelDBFile</code></p></td><td colspan="1"
rowspan="1" class=
"confluenceTd"><p>LevelDBFile</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>Use an existing configured
<code>org.apache.camel.component.leveldb.LevelDBFile</code>
instance.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>sync</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>boolean</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><strong>Camel 2.12:</strong> Whether or not the
LevelDBFile should sync on write or not. Default is false. By sync on write
ensures that its always waiting for all writes to be spooled to disk and thus
will not loose updates. See <a shape="rect" class="external-link"
href="http://leveldb.googlecode.com/svn/trunk/doc/index.html"
rel="nofollow">LevelDB docs</a> for more details about async vs sync
writes.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>returnOldExchange</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>boolean</p></td><td colspan=
"1" rowspan="1" class="confluenceTd"><p>Whether the get operation should
return the old existing Exchange if any existed. By default this option is
<code>false</code> to optimize as we do not need the old exchange when
aggregating.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>useRecovery</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>boolean</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>Whether or not recovery is enabled. This option is by
default <code>true</code>. When enabled the Camel <a shape="rect"
href="aggregator2.html">Aggregator</a> automatic recover failed aggregated
exchange and have them resubmitted.</p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>recoveryInterval</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>long</p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>If recovery is enabled then a background
task is run every x'th time to scan for failed
exchanges to recover and resubmit. By default this interval is 5000
millis.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>maximumRedeliveries</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>int</p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Allows you to limit the maximum number of
redelivery attempts for a recovered exchange. If enabled then the Exchange will
be moved to the dead letter channel if all redelivery attempts failed. By
default this option is disabled. If this option is used then the
<code>deadLetterUri</code> option must also be provided.</p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>deadLetterUri</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>String</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>An endpoint uri for a <a shape="rect"
href="dead-letter-channel.html">Dead Letter Channel</a> where exhausted
recovered Exchanges will be moved. If this o
ption is used then the <code>maximumRedeliveries</code> option must also be
provided.</p></td></tr></tbody></table></div><p>The <code>repositoryName</code>
option must be provided. Then either the <code>persistentFileName</code> or the
<code>levelDBFile</code> must be provided.</p><h3
id="LevelDB-Whatispreservedwhenpersisting">What is preserved when
persisting</h3><p><code>LevelDBAggregationRepository</code> will only preserve
any <code>Serializable</code> compatible message body data types. Message
headers must be primitive / string / numbers / etc. If a data type is not such
a type its dropped and a <code>WARN</code> is logged. And it only persists the
<code>Message</code> body and the <code>Message</code> headers. The
<code>Exchange</code> properties are <strong>not</strong> persisted.</p><h3
id="LevelDB-Recovery">Recovery</h3><p>The
<code>LevelDBAggregationRepository</code> will by default recover any failed <a
shape="rect" href="exchange.html">Exchange</a>. It does this by havi
ng a background tasks that scans for failed <a shape="rect"
href="exchange.html">Exchange</a>s in the persistent store. You can use the
<code>checkInterval</code> option to set how often this task runs. The recovery
works as transactional which ensures that Camel will try to recover and
redeliver the failed <a shape="rect" href="exchange.html">Exchange</a>. Any <a
shape="rect" href="exchange.html">Exchange</a> which was found to be recovered
will be restored from the persistent store and resubmitted and send out
again.</p><p>The following headers is set when an <a shape="rect"
href="exchange.html">Exchange</a> is being recovered/redelivered:</p><div
class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1"
rowspan="1" class="confluenceTh"><p>Header</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Type</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Description</p></th></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>Exchang
e.REDELIVERED</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>Boolean</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>Is set to true to indicate the <a shape="rect"
href="exchange.html">Exchange</a> is being redelivered.</p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>Exchange.REDELIVERY_COUNTER</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>Integer</p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>The redelivery attempt, starting from
1.</p></td></tr></tbody></table></div><p>Only when an <a shape="rect"
href="exchange.html">Exchange</a> has been successfully processed it will be
marked as complete which happens when the <code>confirm</code> method is
invoked on the <code>AggregationRepository</code>. This means if the same <a
shape="rect" href="exchange.html">Exchange</a> fails again it will be kept
retried until it success.</p><p>You can use option
<code>maximumRedeliveries</code> to limit the
maximum number of redelivery attempts for a given recovered <a shape="rect"
href="exchange.html">Exchange</a>. You must also set the
<code>deadLetterUri</code> option so Camel knows where to send the <a
shape="rect" href="exchange.html">Exchange</a> when the
<code>maximumRedeliveries</code> was hit.</p><p>You can see some examples in
the unit tests of camel-leveldb, for example <a shape="rect"
class="external-link"
href="https://svn.apache.org/repos/asf/camel/trunk/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/LevelDBAggregateRecoverTest.java">this
test</a>.</p><h4 id="LevelDB-UsingLevelDBAggregationRepositoryinJavaDSL">Using
LevelDBAggregationRepository in Java DSL</h4><p>In this example we want to
persist aggregated messages in the <code>target/data/leveldb.dat</code>
file.<plain-text-body>{snippet:id=e1|lang=java|url=camel/trunk/components/camel-leveldb/src/test/java/org/apache/camel/component/leveldb/LevelDBAggregateTest.java}</plain-text-body></p><h4
id="LevelDB-UsingLevelDBAggregationRepositoryinSpringXML">Using
LevelDBAggregationRepository in Spring XML</h4><p>The same example but using
Spring XML
instead:<plain-text-body>{snippet:id=e1|lang=xml|url=camel/trunk/components/camel-leveldb/src/test/resources/org/apache/camel/component/leveldb/LevelDBSpringAggregateTest.xml}</plain-text-body></p><h3
id="LevelDB-Dependencies">Dependencies</h3><p>To use <a shape="rect"
href="leveldb.html">LevelDB</a> in your camel routes you need to add the a
dependency on <strong>camel-leveldb</strong>.</p><p>If you use maven you could
just add the following to your pom.xml, substituting the version number for the
latest & greatest release (see <a shape="rect" href="download.html">the
download page for the latest versions</a>).</p><parameter
ac:name="">xml</parameter><plain-text-body><dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-leveldb</artifactId>
<version>2.10.0</version>
</dependency>
-]]></script>
-</div></div><p></p><h3 id="LevelDB-SeeAlso">See Also</h3>
-<ul><li><a shape="rect" href="configuring-camel.html">Configuring
Camel</a></li><li><a shape="rect"
href="component.html">Component</a></li><li><a shape="rect"
href="endpoint.html">Endpoint</a></li><li><a shape="rect"
href="getting-started.html">Getting Started</a></li></ul><ul
class="alternate"><li><a shape="rect"
href="aggregator2.html">Aggregator</a></li><li><a shape="rect"
href="hawtdb.html">HawtDB</a></li><li><a shape="rect"
href="components.html">Components</a></li></ul></div>
+</plain-text-body><p><parameter ac:name=""><a shape="rect"
href="endpoint-see-also.html">Endpoint See Also</a></parameter></p><ul
class="alternate"><li><a shape="rect"
href="aggregator2.html">Aggregator</a></li><li><a shape="rect"
href="hawtdb.html">HawtDB</a></li><li><a shape="rect"
href="components.html">Components</a></li></ul></div>
</td>
<td valign="top">
<div class="navigation">
Modified: websites/production/camel/content/message-filter.html
==============================================================================
--- websites/production/camel/content/message-filter.html (original)
+++ websites/production/camel/content/message-filter.html Fri Aug 25 09:20:43
2017
@@ -36,17 +36,6 @@
<![endif]-->
- <link href='//camel.apache.org/styles/highlighter/styles/shCoreCamel.css'
rel='stylesheet' type='text/css' />
- <link href='//camel.apache.org/styles/highlighter/styles/shThemeCamel.css'
rel='stylesheet' type='text/css' />
- <script src='//camel.apache.org/styles/highlighter/scripts/shCore.js'
type='text/javascript'></script>
- <script src='//camel.apache.org/styles/highlighter/scripts/shBrushJava.js'
type='text/javascript'></script>
- <script src='//camel.apache.org/styles/highlighter/scripts/shBrushXml.js'
type='text/javascript'></script>
- <script src='//camel.apache.org/styles/highlighter/scripts/shBrushPlain.js'
type='text/javascript'></script>
-
- <script type="text/javascript">
- SyntaxHighlighter.defaults['toolbar'] = false;
- SyntaxHighlighter.all();
- </script>
<title>
Apache Camel: Message Filter
@@ -86,72 +75,26 @@
<tbody>
<tr>
<td valign="top" width="100%">
-<div class="wiki-content maincontent"><h3
id="MessageFilter-MessageFilter">Message Filter</h3><p>The <a shape="rect"
class="external-link"
href="http://www.enterpriseintegrationpatterns.com/Filter.html"
rel="nofollow">Message Filter</a> from the <a shape="rect"
href="enterprise-integration-patterns.html">EIP patterns</a> allows you to
filter messages</p><p><span class="confluence-embedded-file-wrapper"><img
class="confluence-embedded-image confluence-external-resource"
src="http://www.enterpriseintegrationpatterns.com/img/MessageFilter.gif"
data-image-src="http://www.enterpriseintegrationpatterns.com/img/MessageFilter.gif"></span></p><p>The
following example shows how to create a Message Filter route consuming
messages from an endpoint called <strong><code>queue:a</code></strong>, which
if the <a shape="rect" href="predicate.html">Predicate</a> is true will be
dispatched to <strong><code>queue:b</code></strong></p><p><strong>Using
the <a shape="rect" href="fluent-builders.html"
>Fluent Builders</a></strong></p><div class="code panel pdl"
>style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
-RouteBuilder builder = new RouteBuilder() {
- public void configure() {
- errorHandler(deadLetterChannel("mock:error"));
-
- from("direct:a")
- .filter(header("foo").isEqualTo("bar"))
- .to("direct:b");
- }
-};
-]]></script>
-</div></div>You can, of course, use many different <a shape="rect"
href="predicate.html">Predicate</a> languages such as <a shape="rect"
href="xpath.html">XPath</a>, <a shape="rect" href="xquery.html">XQuery</a>, <a
shape="rect" href="sql.html">SQL</a> or various <a shape="rect"
href="scripting-languages.html">Scripting Languages</a>. Here is an <a
shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/XPathFilterTest.java">XPath
example</a><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
-from("direct:start").
- filter().xpath("/person[@name='James']").
- to("mock:result");
-]]></script>
-</div></div>Here's another example of using a bean to define the filter
behavior:<div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[from("direct:start")
- .filter().method(MyBean.class,
"isGoldCustomer").to("mock:result").end()
- .to("mock:end");
+<div class="wiki-content maincontent"><h3
id="MessageFilter-MessageFilter">Message Filter</h3><p>The <a shape="rect"
class="external-link"
href="http://www.enterpriseintegrationpatterns.com/Filter.html"
rel="nofollow">Message Filter</a> from the <a shape="rect"
href="enterprise-integration-patterns.html">EIP patterns</a> allows you to
filter messages</p><p><span class="confluence-embedded-file-wrapper"><img
class="confluence-embedded-image confluence-external-resource"
src="http://www.enterpriseintegrationpatterns.com/img/MessageFilter.gif"
data-image-src="http://www.enterpriseintegrationpatterns.com/img/MessageFilter.gif"></span></p><p>The
following example shows how to create a Message Filter route consuming
messages from an endpoint called <strong><code>queue:a</code></strong>, which
if the <a shape="rect" href="predicate.html">Predicate</a> is true will be
dispatched to <strong><code>queue:b</code></strong></p><p><strong>Using
the <a shape="rect" href="fluent-builders.html"
>Fluent
>Builders</a></strong><plain-text-body>{snippet:id=e2|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/builder/RouteBuilderTest.java}</plain-text-body>You
> can, of course, use many different <a shape="rect"
>href="predicate.html">Predicate</a> languages such as <a shape="rect"
>href="xpath.html">XPath</a>, <a shape="rect" href="xquery.html">XQuery</a>,
><a shape="rect" href="sql.html">SQL</a> or various <a shape="rect"
>href="scripting-languages.html">Scripting Languages</a>. Here is an <a
>shape="rect" class="external-link"
>href="http://svn.apache.org/repos/asf/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/XPathFilterTest.java">XPath
>
>example</a><plain-text-body>{snippet:id=example|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/XPathFilterTest.java}</plain-text-body>Here's
> another example of using a bean to define the filter behavior:</p><parameter
>ac:name="language">java</parameter><plain-text-body>from("direct:st
art")
+ .filter().method(MyBean.class, "isGoldCustomer").to("mock:result").end()
+ .to("mock:end");
public static class MyBean {
- public boolean isGoldCustomer(@Header("level") String level) {
- return level.equals("gold");
+ public boolean isGoldCustomer(@Header("level") String level) {
+ return level.equals("gold");
}
}
-]]></script>
-</div></div><p><strong>Using the <a shape="rect"
href="spring-xml-extensions.html">Spring XML Extensions</a></strong></p><div
class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
-<camelContext errorHandlerRef="errorHandler"
xmlns="http://camel.apache.org/schema/spring">
- <route>
- <from uri="direct:a"/>
- <filter>
- <xpath>$foo = 'bar'</xpath>
- <to uri="direct:b"/>
- </filter>
- </route>
-</camelContext>
-]]></script>
-</div></div>You can also use a method call expression (to call a method on a
bean) in the Message Filter, as shown below:<div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[<bean id="myBean"
class="com.foo.MyBean"/>
+</plain-text-body><p><strong>Using the <a shape="rect"
href="spring-xml-extensions.html">Spring XML
Extensions</a></strong><plain-text-body>{snippet:id=example|lang=xml|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/xml/buildSimpleRouteWithHeaderPredicate.xml}</plain-text-body>You
can also use a method call expression (to call a method on a bean) in the
Message Filter, as shown below:</p><parameter
ac:name="language">xml</parameter><plain-text-body><bean id="myBean"
class="com.foo.MyBean"/>
-<camelContext xmlns="http://camel.apache.org/schema/spring">
+<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
- <from uri="direct:a"/>
+ <from uri="direct:a"/>
<filter>
- <method ref="myBean"
method="isGoldCustomer"/>
- <to uri="direct:b"/>
+ <method ref="myBean" method="isGoldCustomer"/>
+ <to uri="direct:b"/>
</filter>
</route>
-</camelContext>]]></script>
-</div></div><div class="confluence-information-macro
confluence-information-macro-information"><p class="title">Filtered Endpoint
Required Inside </filter> Tag</p><span class="aui-icon aui-icon-small
aui-iconfont-info confluence-information-macro-icon"></span><div
class="confluence-information-macro-body"><p>Ensure you put the endpoint you
want to filter <strong><code><to uri="seda:b"/></code></strong> before
the closing <strong><code></filter></code></strong> tag or the
filter will not be applied. From <strong>Camel 2.8</strong>: omitting this will
result in an error.</p></div></div><p>For further examples of this pattern in
use you could look at the <a shape="rect" class="external-link"
href="http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/FilterTest.java?view=markup">junit
test case</a></p><h4 id="MessageFilter-Usingstop()"><span style="line-height:
1.5;">Using <code>stop()</code></span><strong style="line-h
eight: 1.4285715;"><br clear="none" style="line-height:
1.5;"></strong></h4><p>Stop is a bit different than a message filter as it will
filter out all messages and end the route entirely (filter only applies to its
child processor). Stop is convenient to use in a <a shape="rect"
href="content-based-router.html">Content Based Router</a> when you for example
need to stop further processing in one of the predicates.</p><p>In the example
below we do not want to route messages any further that has the word
<strong><code>Bye</code></strong> in the message body. Notice how we prevent
this in the <strong><code>when()</code></strong> predicate by using the
<strong><code>.stop()</code></strong>.</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
-from("direct:start")
- .choice()
- .when(body().contains("Hello")).to("mock:hello")
- .when(body().contains("Bye")).to("mock:bye").stop()
- .otherwise().to("mock:other")
- .end()
- .to("mock:result");
-]]></script>
-</div></div><h4 id="MessageFilter-HowToDetermineIfAnWasFiltered">How To
Determine If An  <a shape="rect" href="exchange.html">Exchange</a> Was
Filtered</h4><p><strong>Available as of Camel 2.5</strong></p><p>The <a
shape="rect" href="message-filter.html">Message Filter</a> EIP will add a
property on the <a shape="rect" href="exchange.html">Exchange</a> that states
if it was filtered or not.</p><p>The property has the key
<strong><code>Exchange.FILTER_MATCHED</code></strong>, which has the String
value of <strong><code>CamelFilterMatched</code></strong>. Its value is
a <strong><code>boolean</code></strong> indicating
<strong><code>true</code></strong> or <strong><code>false</code></strong>. If
the value is <strong><code>true</code></strong> then the <a shape="rect"
href="exchange.html">Exchange</a> was routed in the filter block. This property
will be visible within the <a shape="rect" href="message-filter.html">Message
Filter</a> block who's <a shape="rect" href="predicate
.html">Predicate</a> matches (value set to
<strong><code>true</code></strong>), and to the steps immediately following the
<a shape="rect" href="message-filter.html">Message Filter</a> with the value
set based on the results of the last <a shape="rect"
href="message-filter.html">Message Filter</a> <a shape="rect"
href="predicate.html">Predicate</a> evaluated.</p><p></p><h4
id="MessageFilter-UsingThisPattern">Using This Pattern</h4>
-
-<p>If you would like to use this EIP Pattern then please read the <a
shape="rect" href="getting-started.html">Getting Started</a>, you may also find
the <a shape="rect" href="architecture.html">Architecture</a> useful
particularly the description of <a shape="rect"
href="endpoint.html">Endpoint</a> and <a shape="rect"
href="uris.html">URIs</a>. Then you could try out some of the <a shape="rect"
href="examples.html">Examples</a> first before trying this pattern
out.</p></div>
+</camelContext></plain-text-body><parameter ac:name="title">Filtered
Endpoint Required Inside </filter>
Tag</parameter><rich-text-body><p>Ensure you put the endpoint you want to
filter <strong><code><to uri="seda:b"/></code></strong> before the
closing <strong><code></filter></code></strong> tag or the filter
will not be applied. From <strong>Camel 2.8</strong>: omitting this will result
in an error.</p></rich-text-body><p>For further examples of this pattern in use
you could look at the <a shape="rect" class="external-link"
href="http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/FilterTest.java?view=markup">junit
test case</a></p><h4 id="MessageFilter-Usingstop()"><span style="line-height:
1.5;">Using <code>stop()</code></span><strong style="line-height:
1.4285715;"><br clear="none" style="line-height: 1.5;"></strong></h4><p>Stop is
a bit different than a message filter as it will filter out all messages a
nd end the route entirely (filter only applies to its child processor). Stop
is convenient to use in a <a shape="rect"
href="content-based-router.html">Content Based Router</a> when you for example
need to stop further processing in one of the predicates.</p><p>In the example
below we do not want to route messages any further that has the word
<strong><code>Bye</code></strong> in the message body. Notice how we prevent
this in the <strong><code>when()</code></strong> predicate by using the
<strong><code>.stop()</code></strong>.<plain-text-body>{snippet:id=e1|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RouteStopTest.java}</plain-text-body></p><h4
id="MessageFilter-HowToDetermineIfAnWasFiltered">How To Determine If An 
<a shape="rect" href="exchange.html">Exchange</a> Was
Filtered</h4><p><strong>Available as of Camel 2.5</strong></p><p>The <a
shape="rect" href="message-filter.html">Message Filter</a> EIP will add a
property on the <a shape="
rect" href="exchange.html">Exchange</a> that states if it was filtered or
not.</p><p>The property has the key
<strong><code>Exchange.FILTER_MATCHED</code></strong>, which has the String
value of <strong><code>CamelFilterMatched</code></strong>. Its value is
a <strong><code>boolean</code></strong> indicating
<strong><code>true</code></strong> or <strong><code>false</code></strong>. If
the value is <strong><code>true</code></strong> then the <a shape="rect"
href="exchange.html">Exchange</a> was routed in the filter block. This property
will be visible within the <a shape="rect" href="message-filter.html">Message
Filter</a> block who's <a shape="rect" href="predicate.html">Predicate</a>
matches (value set to <strong><code>true</code></strong>), and to the steps
immediately following the <a shape="rect" href="message-filter.html">Message
Filter</a> with the value set based on the results of the last <a shape="rect"
href="message-filter.html">Message Filter</a> <a shape="rect" href=
"predicate.html">Predicate</a> evaluated.</p><p><parameter ac:name=""><a
shape="rect" href="using-this-pattern.html">Using This
Pattern</a></parameter></p></div>
</td>
<td valign="top">
<div class="navigation">
Modified: websites/production/camel/content/message-translator.html
==============================================================================
--- websites/production/camel/content/message-translator.html (original)
+++ websites/production/camel/content/message-translator.html Fri Aug 25
09:20:43 2017
@@ -36,17 +36,6 @@
<![endif]-->
- <link href='//camel.apache.org/styles/highlighter/styles/shCoreCamel.css'
rel='stylesheet' type='text/css' />
- <link href='//camel.apache.org/styles/highlighter/styles/shThemeCamel.css'
rel='stylesheet' type='text/css' />
- <script src='//camel.apache.org/styles/highlighter/scripts/shCore.js'
type='text/javascript'></script>
- <script src='//camel.apache.org/styles/highlighter/scripts/shBrushJava.js'
type='text/javascript'></script>
- <script src='//camel.apache.org/styles/highlighter/scripts/shBrushXml.js'
type='text/javascript'></script>
- <script src='//camel.apache.org/styles/highlighter/scripts/shBrushPlain.js'
type='text/javascript'></script>
-
- <script type="text/javascript">
- SyntaxHighlighter.defaults['toolbar'] = false;
- SyntaxHighlighter.all();
- </script>
<title>
Apache Camel: Message Translator
@@ -96,87 +85,52 @@
<p>You can transform a message using Camel's <a shape="rect"
href="bean-integration.html">Bean Integration</a> to call any method on a bean
in your <a shape="rect" href="registry.html">Registry</a> such as your <a
shape="rect" href="spring.html">Spring</a> XML configuration file as follows</p>
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
-from("activemq:SomeQueue").
- beanRef("myTransformerBean", "myMethodName").
- to("mqseries:AnotherQueue");
-]]></script>
-</div></div>
+<plain-text-body>
+from("activemq:SomeQueue").
+ beanRef("myTransformerBean", "myMethodName").
+ to("mqseries:AnotherQueue");
+</plain-text-body>
<p>Where the "myTransformerBean" would be defined in a Spring XML file or
defined in JNDI etc. You can omit the method name parameter from beanRef() and
the <a shape="rect" href="bean-integration.html">Bean Integration</a> will try
to deduce the method to invoke from the message exchange.</p>
<p>or you can add your own explicit <a shape="rect"
href="processor.html">Processor</a> to do the transformation</p>
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
-from("direct:start").process(new Processor() {
- public void process(Exchange exchange) {
- Message in = exchange.getIn();
- in.setBody(in.getBody(String.class) + " World!");
- }
-}).to("mock:result");
-]]></script>
-</div></div>
+<plain-text-body>{snippet:id=example|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/TransformTest.java}</plain-text-body>
<p>or you can use the DSL to explicitly configure the transformation</p>
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
-from("direct:start").transform(body().append("
World!")).to("mock:result");
-]]></script>
-</div></div>
+<plain-text-body>{snippet:id=example|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/TransformProcessorTest.java}</plain-text-body>
<p><strong>Use Spring XML</strong></p>
<p>You can also use <a shape="rect" href="spring-xml-extensions.html">Spring
XML Extensions</a> to do a transformation. Basically any <a shape="rect"
href="expression.html">Expression</a> language can be substituted inside the
transform element as shown below</p>
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
-<camelContext xmlns="http://camel.apache.org/schema/spring">
- <route>
- <from uri="direct:start"/>
- <transform>
- <simple>${in.body} extra data!</simple>
- </transform>
- <to uri="mock:end"/>
- </route>
-</camelContext>
-]]></script>
-</div></div>
+<plain-text-body>{snippet:id=example|lang=xml|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/transformWithExpressionContext.xml}</plain-text-body>
<p>Or you can use the <a shape="rect" href="bean-integration.html">Bean
Integration</a> to invoke a bean</p>
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
+<plain-text-body>
<route>
- <from uri="activemq:Input"/>
- <bean ref="myBeanName" method="doTransform"/>
- <to uri="activemq:Output"/>
+ <from uri="activemq:Input"/>
+ <bean ref="myBeanName" method="doTransform"/>
+ <to uri="activemq:Output"/>
</route>
-]]></script>
-</div></div>
+</plain-text-body>
<p>You can also use <a shape="rect" href="templating.html">Templating</a> to
consume a message from one destination, transform it with something like <a
shape="rect" href="velocity.html">Velocity</a> or <a shape="rect"
href="xquery.html">XQuery</a> and then send it on to another destination. For
example using InOnly (one way messaging)</p>
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
-from("activemq:My.Queue").
- to("velocity:com/acme/MyResponse.vm").
- to("activemq:Another.Queue");
-]]></script>
-</div></div>
+<plain-text-body>
+from("activemq:My.Queue").
+ to("velocity:com/acme/MyResponse.vm").
+ to("activemq:Another.Queue");
+</plain-text-body>
<p>If you want to use InOut (request-reply) semantics to process requests on
the <strong>My.Queue</strong> queue on <a shape="rect"
href="activemq.html">ActiveMQ</a> with a template generated response, then
sending responses back to the JMSReplyTo Destination you could use this.</p>
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
-from("activemq:My.Queue").
- to("velocity:com/acme/MyResponse.vm");
-]]></script>
-</div></div>
-
+<plain-text-body>
+from("activemq:My.Queue").
+ to("velocity:com/acme/MyResponse.vm");
+</plain-text-body>
-<h4 id="MessageTranslator-UsingThisPattern">Using This Pattern</h4>
-<p>If you would like to use this EIP Pattern then please read the <a
shape="rect" href="getting-started.html">Getting Started</a>, you may also find
the <a shape="rect" href="architecture.html">Architecture</a> useful
particularly the description of <a shape="rect"
href="endpoint.html">Endpoint</a> and <a shape="rect"
href="uris.html">URIs</a>. Then you could try out some of the <a shape="rect"
href="examples.html">Examples</a> first before trying this pattern out.</p>
+<parameter ac:name=""><a shape="rect" href="using-this-pattern.html">Using
This Pattern</a></parameter>
<ul class="alternate"><li><a shape="rect" href="content-enricher.html">Content
Enricher</a></li><li><a shape="rect"
href="using-getin-or-getout-methods-on-exchange.html">Using getIn or getOut
methods on Exchange</a></li></ul></div>
</td>
<td valign="top">
Modified: websites/production/camel/content/multicast.html
==============================================================================
--- websites/production/camel/content/multicast.html (original)
+++ websites/production/camel/content/multicast.html Fri Aug 25 09:20:43 2017
@@ -36,17 +36,6 @@
<![endif]-->
- <link href='//camel.apache.org/styles/highlighter/styles/shCoreCamel.css'
rel='stylesheet' type='text/css' />
- <link href='//camel.apache.org/styles/highlighter/styles/shThemeCamel.css'
rel='stylesheet' type='text/css' />
- <script src='//camel.apache.org/styles/highlighter/scripts/shCore.js'
type='text/javascript'></script>
- <script src='//camel.apache.org/styles/highlighter/scripts/shBrushJava.js'
type='text/javascript'></script>
- <script src='//camel.apache.org/styles/highlighter/scripts/shBrushXml.js'
type='text/javascript'></script>
- <script src='//camel.apache.org/styles/highlighter/scripts/shBrushPlain.js'
type='text/javascript'></script>
-
- <script type="text/javascript">
- SyntaxHighlighter.defaults['toolbar'] = false;
- SyntaxHighlighter.all();
- </script>
<title>
Apache Camel: Multicast
@@ -86,159 +75,49 @@
<tbody>
<tr>
<td valign="top" width="100%">
-<div class="wiki-content maincontent"><h3
id="Multicast-Multicast">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><h3 id="Multicast-Options">Options</h3><div
class="confluenceTableSmall"><div class="table-wrap"><table
class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1"
class="confluenceTh"><p>Name</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Default Value</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Description</p></th></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>strategyRef</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p> </p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Refers to an <a shape="rect"
class="external-link" href="http://came
l.apache.org/maven/current/camel-core/apidocs/org/apache/camel/processor/aggregate/AggregationStrategy.html">AggregationStrategy</a>
to be used to assemble the replies from the multicasts, into a single outgoing
message from the <a shape="rect" href="multicast.html">Multicast</a>. By
default Camel will use the last reply as the outgoing message. From
<strong>Camel 2.12</strong> onwards you can also use a POJO as the
<code>AggregationStrategy</code>, see the <a shape="rect"
href="aggregator2.html">Aggregate</a> page for more details. If an exception is
thrown from the aggregate method in the AggregationStrategy, then by default,
that exception is not handled by the error handler. The error handler can
be enabled to react if enabling the shareUnitOfWork
option.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>strategyMethodName</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p> </p></td><td colspan="1" rowspan="1"
class="confluenceT
d"><p><strong>Camel 2.12:</strong> This option can be used to explicit declare
the method name to use, when using POJOs as the
<code>AggregationStrategy</code>. See the <a shape="rect"
href="aggregator2.html">Aggregate</a> page for more
details.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>strategyMethodAllowNull</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.12:</strong> If
this option is <code>false</code> then the aggregate method is not used if
there was no data to enrich. If this option is <code>true</code> then
<code>null</code> values is used as the <code>oldExchange</code> (when no data
to enrich), when using POJOs as the <code>AggregationStrategy</code>. See the
<a shape="rect" href="aggregator2.html">Aggregate</a> page for more
details.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>parallelProcessing</
code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>false</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>If enabled then sending messages to the multicasts
occurs concurrently. Note the caller thread will still wait until all messages
has been fully processed, before it continues. Its only the sending and
processing the replies from the multicasts which happens
concurrently.</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p> </p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>parallelAggregate</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>Camel 2.14:</strong> If enabled
then the <code>aggregate</code> method on <code>AggregationStrategy</code> can
be called concurrently. Notice that this would require the implementation of
<code>AggregationStrategy</code> to be implemented as thread-safe. By default
this is <code>false</code> meaning that Camel synchronizes the call to the
<code>aggregate</code> method. Though in some use-cases this can be used to
archive higher performance when the <code>AggregationStrategy</code> is
implemented as thread-safe.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>executorServiceRef</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p> </p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>Refers to a custom <a shape="rect"
href="threading-model.html">Thread Pool</a> to be used for parallel processing.
Notice if you set this option, then parallel processing is automatic implied,
and you do not have to enable that option as well.</p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>stopOnException</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>Camel 2.2:</strong> Whether
or not to stop continue processing immediately when an exception occurred. If
disable, then Camel will send the message to all multicasts regardless if one
of them failed. You can deal with exceptions in the <a shape="rect"
class="external-link"
href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/processor/aggregate/AggregationStrategy.html">AggregationStrategy</a>
class where you have full control how to handle that.</p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>streaming</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>If enabled then Camel will process replies
out-of-order, eg in the order they come back. If disabled, Camel will process
replies in the same order as multicasted.</p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>timeout</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>
60;</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel
2.5:</strong> Sets a total timeout specified in millis. If the <a shape="rect"
href="multicast.html">Multicast</a> hasn't been able to send and process all
replies within the given timeframe, then the timeout triggers and the <a
shape="rect" href="multicast.html">Multicast</a> breaks out and continues.
Notice if you provide a <a shape="rect" class="external-link"
href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/processor/aggregate/TimeoutAwareAggregationStrategy.html">TimeoutAwareAggregationStrategy</a>
then the <code>timeout</code> method is invoked before breaking out. If the
timeout is reached with running tasks still remaining, certain tasks for which
it is difficult for Camel to shut down in a graceful manner may continue to
run. So use this option with a bit of care. We may be able to improve this
functionality in future Camel releases.</p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>onPrepareRef</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p> </p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>Camel 2.8:</strong> Refers to a
custom <a shape="rect" href="processor.html">Processor</a> to prepare the copy
of the <a shape="rect" href="exchange.html">Exchange</a> each multicast will
receive. This allows you to do any custom logic, such as deep-cloning the
message payload if that's needed etc.</p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>shareUnitOfWork</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.8:</strong>
Whether the unit of work should be shared. See the same option on <a
shape="rect" href="splitter.html">Splitter</a> for more
details.</p></td></tr></tbody></table></div></div>
-
-
-<h4 id="Multicast-Example">Example</h4><p>The following example shows how to
take a request from the <strong>direct:a</strong> endpoint , then multicast
these request to <strong>direct:x</strong>, <strong>direct:y</strong>,
<strong>direct:z</strong>.</p><p><strong>Using the <a shape="rect"
href="fluent-builders.html">Fluent Builders</a></strong></p><div class="code
panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
-from("direct:a").multicast().to("direct:x",
"direct:y", "direct:z");
-]]></script>
-</div></div>By default Multicast invokes each endpoint sequentially. If
parallel processing is desired, simply use<div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[from("direct:a").multicast().parallelProcessing().to("direct:x",
"direct:y", "direct:z");
-]]></script>
-</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 pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[from("direct:start")
+<div class="wiki-content maincontent"><h3
id="Multicast-Multicast">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><h3 id="Multicast-Options">Options</h3><parameter
ac:name="class">confluenceTableSmall</parameter><rich-text-body><div
class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1"
rowspan="1" class="confluenceTh"><p>Name</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Default Value</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Description</p></th></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>strategyRef</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p> </p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Refers to an <a shape="rect
" class="external-link"
href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/processor/aggregate/AggregationStrategy.html">AggregationStrategy</a>
to be used to assemble the replies from the multicasts, into a single outgoing
message from the <a shape="rect" href="multicast.html">Multicast</a>. By
default Camel will use the last reply as the outgoing message. From
<strong>Camel 2.12</strong> onwards you can also use a POJO as the
<code>AggregationStrategy</code>, see the <a shape="rect"
href="aggregator2.html">Aggregate</a> page for more details. If an exception is
thrown from the aggregate method in the AggregationStrategy, then by default,
that exception is not handled by the error handler. The error handler can
be enabled to react if enabling the shareUnitOfWork
option.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>strategyMethodName</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p> </p></td><td c
olspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.12:</strong>
This option can be used to explicit declare the method name to use, when using
POJOs as the <code>AggregationStrategy</code>. See the <a shape="rect"
href="aggregator2.html">Aggregate</a> page for more
details.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>strategyMethodAllowNull</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.12:</strong> If
this option is <code>false</code> then the aggregate method is not used if
there was no data to enrich. If this option is <code>true</code> then
<code>null</code> values is used as the <code>oldExchange</code> (when no data
to enrich), when using POJOs as the <code>AggregationStrategy</code>. See the
<a shape="rect" href="aggregator2.html">Aggregate</a> page for more
details.</p></td></tr><tr><td colspan="1" rowspan="1" class="co
nfluenceTd"><p><code>parallelProcessing</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>If enabled then sending messages to the
multicasts occurs concurrently. Note the caller thread will still wait until
all messages has been fully processed, before it continues. Its only the
sending and processing the replies from the multicasts which happens
concurrently.</p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p> </p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>parallelAggregate</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>Camel 2.14:</strong> If enabled
then the <code>aggregate</code> method on <code>AggregationStrategy</code> can
be called concurrently. Notice that this would require the implementation of
<code>AggregationStrategy</code> to
be implemented as thread-safe. By default this is <code>false</code> meaning
that Camel synchronizes the call to the <code>aggregate</code> method. Though
in some use-cases this can be used to archive higher performance when the
<code>AggregationStrategy</code> is implemented as
thread-safe.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>executorServiceRef</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p> </p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>Refers to a custom <a shape="rect"
href="threading-model.html">Thread Pool</a> to be used for parallel processing.
Notice if you set this option, then parallel processing is automatic implied,
and you do not have to enable that option as well.</p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>stopOnException</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd
"><p><strong>Camel 2.2:</strong> Whether or not to stop continue processing
immediately when an exception occurred. If disable, then Camel will send the
message to all multicasts regardless if one of them failed. You can deal with
exceptions in the <a shape="rect" class="external-link"
href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/processor/aggregate/AggregationStrategy.html">AggregationStrategy</a>
class where you have full control how to handle that.</p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>streaming</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>If enabled then Camel will process replies
out-of-order, eg in the order they come back. If disabled, Camel will process
replies in the same order as multicasted.</p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>timeout</code></p></td><td colspan="1
" rowspan="1" class="confluenceTd"><p> </p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>Camel 2.5:</strong> Sets a total
timeout specified in millis. If the <a shape="rect"
href="multicast.html">Multicast</a> hasn't been able to send and process all
replies within the given timeframe, then the timeout triggers and the <a
shape="rect" href="multicast.html">Multicast</a> breaks out and continues.
Notice if you provide a <a shape="rect" class="external-link"
href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/processor/aggregate/TimeoutAwareAggregationStrategy.html">TimeoutAwareAggregationStrategy</a>
then the <code>timeout</code> method is invoked before breaking out. If the
timeout is reached with running tasks still remaining, certain tasks for which
it is difficult for Camel to shut down in a graceful manner may continue to
run. So use this option with a bit of care. We may be able to improve this
functionality in future Camel re
leases.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>onPrepareRef</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p> </p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><strong>Camel 2.8:</strong> Refers to a custom <a
shape="rect" href="processor.html">Processor</a> to prepare the copy of the <a
shape="rect" href="exchange.html">Exchange</a> each multicast will receive.
This allows you to do any custom logic, such as deep-cloning the message
payload if that's needed etc.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>shareUnitOfWork</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>Camel 2.8:</strong> Whether the
unit of work should be shared. See the same option on <a shape="rect"
href="splitter.html">Splitter</a> for more
details.</p></td></tr></tbody></table></div></rich-text-body><h4 id="
Multicast-Example">Example</h4><p>The following example shows how to take a
request from the <strong>direct:a</strong> endpoint , then multicast these
request to <strong>direct:x</strong>, <strong>direct:y</strong>,
<strong>direct:z</strong>.</p><p><strong>Using the <a shape="rect"
href="fluent-builders.html">Fluent
Builders</a></strong><plain-text-body>{snippet:id=example|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/MulticastTest.java}</plain-text-body>By
default Multicast invokes each endpoint sequentially. If parallel processing
is desired, simply
use</p><plain-text-body>from("direct:a").multicast().parallelProcessing().to("direct:x",
"direct:y", "direct:z");
+</plain-text-body><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><plain-text-body>from("direct:start")
.multicast(new MyAggregationStrategy())
- .parallelProcessing().timeout(500).to("direct:a",
"direct:b", "direct:c")
+ .parallelProcessing().timeout(500).to("direct:a", "direct:b", "direct:c")
.end()
- .to("mock:result");
-]]></script>
-</div></div><h3 id="Multicast-Stopprocessingincaseofexception">Stop processing
in case of exception</h3><p><strong>Available as of Camel
2.1</strong></p><p>The <a shape="rect" href="multicast.html">Multicast</a> will
by default continue to process the entire <a shape="rect"
href="exchange.html">Exchange</a> even in case one of the multicasted messages
will thrown an exception during routing.<br clear="none"> 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
<code>AggregationStrategy</code>.</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 <code>stopOnException</code>
option as shown below:</p><div class="code panel
pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[ from("direct:start")
+ .to("mock:result");
+</plain-text-body><h3 id="Multicast-Stopprocessingincaseofexception">Stop
processing in case of exception</h3><p><strong>Available as of Camel
2.1</strong></p><p>The <a shape="rect" href="multicast.html">Multicast</a> will
by default continue to process the entire <a shape="rect"
href="exchange.html">Exchange</a> even in case one of the multicasted messages
will thrown an exception during routing.<br clear="none"> 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
<code>AggregationStrategy</code>.</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 <code>stopOnException</code>
option as shown below:</p><plain-text-body>
from("direct:start")
.multicast()
- .stopOnException().to("direct:foo",
"direct:bar", "direct:baz")
+ .stopOnException().to("direct:foo", "direct:bar", "direct:baz")
.end()
- .to("mock:result");
+ .to("mock:result");
- from("direct:foo").to("mock:foo");
+ from("direct:foo").to("mock:foo");
- from("direct:bar").process(new
MyProcessor()).to("mock:bar");
+ from("direct:bar").process(new MyProcessor()).to("mock:bar");
- from("direct:baz").to("mock:baz");
-]]></script>
-</div></div><p>And using XML DSL you specify it as follows:</p><div
class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[ <route>
- <from uri="direct:start"/>
- <multicast stopOnException="true">
- <to uri="direct:foo"/>
- <to uri="direct:bar"/>
- <to uri="direct:baz"/>
+ from("direct:baz").to("mock:baz");
+</plain-text-body><p>And using XML DSL you specify it as
follows:</p><parameter ac:name="">xml</parameter><plain-text-body>
<route>
+ <from uri="direct:start"/>
+ <multicast stopOnException="true">
+ <to uri="direct:foo"/>
+ <to uri="direct:bar"/>
+ <to uri="direct:baz"/>
</multicast>
- <to uri="mock:result"/>
+ <to uri="mock:result"/>
</route>
<route>
- <from uri="direct:foo"/>
- <to uri="mock:foo"/>
+ <from uri="direct:foo"/>
+ <to uri="mock:foo"/>
</route>
<route>
- <from uri="direct:bar"/>
- <process ref="myProcessor"/>
- <to uri="mock:bar"/>
+ <from uri="direct:bar"/>
+ <process ref="myProcessor"/>
+ <to uri="mock:bar"/>
</route>
<route>
- <from uri="direct:baz"/>
- <to uri="mock:baz"/>
+ <from uri="direct:baz"/>
+ <to uri="mock:baz"/>
</route>
-]]></script>
-</div></div><h3
id="Multicast-UsingonPreparetoexecutecustomlogicwhenpreparingmessages">Using
onPrepare to execute custom logic when preparing
messages</h3><p><strong>Available as of Camel 2.8</strong></p><p>The <a
shape="rect" href="multicast.html">Multicast</a> will copy the source <a
shape="rect" href="exchange.html">Exchange</a> and multicast each copy. However
the copy is a shallow copy, so in case you have mutateable message bodies, then
any changes will be visible by the other copied messages. If you want to use a
deep clone copy then you need to use a custom <code>onPrepare</code> which
allows you to do this using the <a shape="rect"
href="processor.html">Processor</a> interface.</p><p>Notice the
<code>onPrepare</code> can be used for any kind of custom logic which you would
like to execute before the <a shape="rect" href="exchange.html">Exchange</a> is
being multicasted.</p><div class="confluence-information-macro
confluence-information-macro-tip"><p class="title">Design for
immutable</p><span class="aui-icon aui-icon-small aui-iconfont-approve
confluence-information-macro-icon"></span><div
class="confluence-information-macro-body"><p>Its best practice to design for
immutable objects.</p></div></div><p>For example if you have a mutable message
body as this Animal class:</p><div class="code panel pdl" style="border-width:
1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width:
1px;"><b>Animal</b></div><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
-public class Animal implements Serializable {
- private static final long serialVersionUID = 1L;
- private int id;
- private String name;
-
- public Animal() {
- }
-
- public Animal(int id, String name) {
- this.id = id;
- this.name = name;
- }
-
- public Animal deepClone() {
- Animal clone = new Animal();
- clone.setId(getId());
- clone.setName(getName());
- return clone;
- }
-
- public int getId() {
- return id;
- }
-
- public void setId(int id) {
- this.id = id;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- @Override
- public String toString() {
- return id + " " + name;
- }
-}
-]]></script>
-</div></div>Then we can create a deep clone processor which clones the message
body:<div class="code panel pdl" style="border-width: 1px;"><div
class="codeHeader panelHeader pdl" style="border-bottom-width:
1px;"><b>AnimalDeepClonePrepare</b></div><div class="codeContent panelContent
pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
-public class AnimalDeepClonePrepare implements Processor {
-
- public void process(Exchange exchange) throws Exception {
- Animal body = exchange.getIn().getBody(Animal.class);
-
- // do a deep clone of the body which wont affect when doing
multicasting
- Animal clone = body.deepClone();
- exchange.getIn().setBody(clone);
- }
-}
-]]></script>
-</div></div>Then we can use the AnimalDeepClonePrepare class in the <a
shape="rect" href="multicast.html">Multicast</a> route using the
<code>onPrepare</code> option as shown:<div class="code panel pdl"
style="border-width: 1px;"><div class="codeHeader panelHeader pdl"
style="border-bottom-width: 1px;"><b>Multicast using onPrepare</b></div><div
class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
-from("direct:start")
- .multicast().onPrepare(new
AnimalDeepClonePrepare()).to("direct:a").to("direct:b");
-]]></script>
-</div></div>And the same example in XML DSL<div class="code panel pdl"
style="border-width: 1px;"><div class="codeHeader panelHeader pdl"
style="border-bottom-width: 1px;"><b>Multicast using onPrepare</b></div><div
class="codeContent panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
-<camelContext xmlns="http://camel.apache.org/schema/spring">
- <route>
- <from uri="direct:start"/>
- <!-- use on prepare with multicast -->
- <multicast onPrepareRef="animalDeepClonePrepare">
- <to uri="direct:a"/>
- <to uri="direct:b"/>
- </multicast>
- </route>
-
- <route>
- <from uri="direct:a"/>
- <process ref="processorA"/>
- <to uri="mock:a"/>
- </route>
- <route>
- <from uri="direct:b"/>
- <process ref="processorB"/>
- <to uri="mock:b"/>
- </route>
-</camelContext>
-
-<!-- the on prepare Processor which performs the deep cloning -->
-<bean id="animalDeepClonePrepare"
class="org.apache.camel.processor.AnimalDeepClonePrepare"/>
-
-<!-- processors used for the last two routes, as part of unit test -->
-<bean id="processorA"
class="org.apache.camel.processor.MulticastOnPrepareTest$ProcessorA"/>
-<bean id="processorB"
class="org.apache.camel.processor.MulticastOnPrepareTest$ProcessorB"/>
-]]></script>
-</div></div>Notice the <code>onPrepare</code> option is also available on
other <a shape="rect" href="eip.html">EIP</a>s such as <a shape="rect"
href="splitter.html">Splitter</a>, <a shape="rect"
href="recipient-list.html">Recipient List</a>, and <a shape="rect"
href="wire-tap.html">Wire Tap</a>.<p></p><h4
id="Multicast-UsingThisPattern">Using This Pattern</h4>
-
-<p>If you would like to use this EIP Pattern then please read the <a
shape="rect" href="getting-started.html">Getting Started</a>, you may also find
the <a shape="rect" href="architecture.html">Architecture</a> useful
particularly the description of <a shape="rect"
href="endpoint.html">Endpoint</a> and <a shape="rect"
href="uris.html">URIs</a>. Then you could try out some of the <a shape="rect"
href="examples.html">Examples</a> first before trying this pattern
out.</p></div>
+</plain-text-body><h3
id="Multicast-UsingonPreparetoexecutecustomlogicwhenpreparingmessages">Using
onPrepare to execute custom logic when preparing
messages</h3><p><strong>Available as of Camel 2.8</strong></p><p>The <a
shape="rect" href="multicast.html">Multicast</a> will copy the source <a
shape="rect" href="exchange.html">Exchange</a> and multicast each copy. However
the copy is a shallow copy, so in case you have mutateable message bodies, then
any changes will be visible by the other copied messages. If you want to use a
deep clone copy then you need to use a custom <code>onPrepare</code> which
allows you to do this using the <a shape="rect"
href="processor.html">Processor</a> interface.</p><p>Notice the
<code>onPrepare</code> can be used for any kind of custom logic which you would
like to execute before the <a shape="rect" href="exchange.html">Exchange</a> is
being multicasted.</p><parameter ac:name="title">Design for
immutable</parameter><rich-text-body><p>Its best practice
to design for immutable objects.</p></rich-text-body><p>For example if you
have a mutable message body as this Animal
class:<plain-text-body>{snippet:id=e1|lang=java|title=Animal|url=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/Animal.java}</plain-text-body>Then
we can create a deep clone processor which clones the message
body:<plain-text-body>{snippet:id=e1|lang=java|title=AnimalDeepClonePrepare|url=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/AnimalDeepClonePrepare.java}</plain-text-body>Then
we can use the AnimalDeepClonePrepare class in the <a shape="rect"
href="multicast.html">Multicast</a> route using the <code>onPrepare</code>
option as shown:<plain-text-body>{snippet:id=e1|lang=java|title=Multicast using
onPrepare|url=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/MulticastOnPrepareTest.java}</plain-text-body>And
the same example in XML
DSL<plain-text-body>{snippet:id=e1|lang=xml|title=Multicast using
onPrepare|url=came
l/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/MulticastOnPrepareTest.xml}</plain-text-body>Notice
the <code>onPrepare</code> option is also available on other <a shape="rect"
href="eip.html">EIP</a>s such as <a shape="rect"
href="splitter.html">Splitter</a>, <a shape="rect"
href="recipient-list.html">Recipient List</a>, and <a shape="rect"
href="wire-tap.html">Wire Tap</a>.</p><p><parameter ac:name=""><a shape="rect"
href="using-this-pattern.html">Using This Pattern</a></parameter></p></div>
</td>
<td valign="top">
<div class="navigation">