camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Camel > Splitter
Date Thu, 06 Sep 2012 09:44: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/Splitter">Splitter</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~davsclaus">Claus Ibsen</a>
    </h4>
        <br/>
                         <h4>Changes (1)</h4>
                                 
    
<div id="page-diffs">
                    <table class="diff" cellpadding="0" cellspacing="0">
    
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >| {{stopOnException}} | {{false}} | *Camel 2.2:* Whether or not to stop continue processing immediately when an exception occurred. If disable, then Camel continue splitting and process the sub-messages regardless if one of them failed. You can deal with exceptions in the [AggregationStrategy|http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/processor/aggregate/AggregationStrategy.html] class where you have full control how to handle that. | <br>| {{streaming}} | {{false}} | If enabled then Camel will split in a streaming fashion, which means it will split the input message in chunks. This reduces the memory overhead. For example if you split big messages its recommended to enable streaming. If streaming is enabled then the sub-message replies will be aggregated out-of-order, eg in the order they come back. If disabled, Camel will process sub-message replies in the same order as they where splitted. | <br></td></tr>
            <tr><td class="diff-changed-lines" >| {{timeout}} | | *Camel 2.5:* Sets a total timeout specified in millis. If the [Recipient List] hasn&#39;t been able to split and process all replies within the given timeframe, then the timeout triggers and the [Splitter] breaks out and continues. Notice if you provide a [TimeoutAwareAggregationStrategy|http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/processor/aggregate/TimeoutAwareAggregationStrategy.html] then the {{timeout}} method is invoked before breaking out. <span class="diff-added-words"style="background-color: #dfd;">When a timeout is hit, and there is already running tasks, then these tasks may run for a while, as its hard to cancel/interrupt these tasks in a graceful manner. So use this option with a bit of care. In a future Camel release we may have improved this.</span> | <br></td></tr>
            <tr><td class="diff-unchanged" >| {{onPrepareRef}} | | *Camel 2.8:* Refers to a custom [Processor] to prepare the sub-message of the [Exchange], before its processed. This allows you to do any custom logic, such as deep-cloning the message payload if that&#39;s needed etc. | <br>| {{shareUnitOfWork}} | {{false}} | *Camel 2.8:* Whether the unit of work should be shared. See further below for more details. | <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h3><a name="Splitter-Splitter"></a>Splitter</h3>

<p>The <a href="http://www.enterpriseintegrationpatterns.com/Sequencer.html" class="external-link" rel="nofollow">Splitter</a> from the <a href="/confluence/display/CAMEL/Enterprise+Integration+Patterns" title="Enterprise Integration Patterns">EIP patterns</a> allows you split a message into a number of pieces and process them individually</p>

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

<p>As of Camel 2.0, you need to specify a Splitter as <tt>split()</tt>. In earlier versions of Camel, you need to use <tt>splitter()</tt>.</p>


<h3><a name="Splitter-Options"></a>Options</h3>

<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Default Value </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>strategyRef</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> Refers to an <a href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/processor/aggregate/AggregationStrategy.html" class="external-link" rel="nofollow">AggregationStrategy</a> to be used to assemble the replies from the sub-messages, into a single outgoing message from the <a href="/confluence/display/CAMEL/Splitter" title="Splitter">Splitter</a>. See the defaults described below in <em><a href="#Splitter-WhattheSplitterreturns">What the Splitter returns</a></em>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>parallelProcessing</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> If enables then processing the sub-messages occurs concurrently. Note the caller thread will still wait until all sub-messages has been fully processed, before it continues. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>executorServiceRef</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> Refers to a custom <a href="/confluence/display/CAMEL/Threading+Model" title="Threading Model">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. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>stopOnException</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.2:</b> Whether or not to stop continue processing immediately when an exception occurred. If disable, then Camel continue splitting and process the sub-messages regardless if one of them failed. You can deal with exceptions in the <a href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/processor/aggregate/AggregationStrategy.html" class="external-link" rel="nofollow">AggregationStrategy</a> class where you have full control how to handle that. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>streaming</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> If enabled then Camel will split in a streaming fashion, which means it will split the input message in chunks. This reduces the memory overhead. For example if you split big messages its recommended to enable streaming. If streaming is enabled then the sub-message replies will be aggregated out-of-order, eg in the order they come back. If disabled, Camel will process sub-message replies in the same order as they where splitted. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>timeout</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> <b>Camel 2.5:</b> Sets a total timeout specified in millis. If the <a href="/confluence/display/CAMEL/Recipient+List" title="Recipient List">Recipient List</a> hasn't been able to split and process all replies within the given timeframe, then the timeout triggers and the <a href="/confluence/display/CAMEL/Splitter" title="Splitter">Splitter</a> breaks out and continues. Notice if you provide a <a href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/processor/aggregate/TimeoutAwareAggregationStrategy.html" class="external-link" rel="nofollow">TimeoutAwareAggregationStrategy</a> then the <tt>timeout</tt> method is invoked before breaking out. When a timeout is hit, and there is already running tasks, then these tasks may run for a while, as its hard to cancel/interrupt these tasks in a graceful manner. So use this option with a bit of care. In a future Camel release we may have improved this. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>onPrepareRef</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> <b>Camel 2.8:</b> Refers to a custom <a href="/confluence/display/CAMEL/Processor" title="Processor">Processor</a> to prepare the sub-message of the <a href="/confluence/display/CAMEL/Exchange" title="Exchange">Exchange</a>, before its processed. This allows you to do any custom logic, such as deep-cloning the message payload if that's needed etc. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>shareUnitOfWork</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.8:</b> Whether the unit of work should be shared. See further below for more details. </td>
</tr>
</tbody></table>
</div>
</div>

<h3><a name="Splitter-Exchangeproperties"></a>Exchange properties</h3>
<p>The following properties are set on each Exchange that are split:</p>
<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> property </th>
<th class='confluenceTh'> type </th>
<th class='confluenceTh'> description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelSplitIndex</tt> </td>
<td class='confluenceTd'> int </td>
<td class='confluenceTd'> Camel 2.0: A split counter that increases for each Exchange being split. The counter starts from 0. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelSplitSize</tt> </td>
<td class='confluenceTd'> int </td>
<td class='confluenceTd'> Camel 2.0: The total number of Exchanges that was splitted. This header is not applied for stream based splitting. From <b>Camel 2.9</b> onwards this header is also set in stream based splitting, but only on the completed Exchange. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CamelSplitComplete</tt> </td>
<td class='confluenceTd'> boolean </td>
<td class='confluenceTd'> <b>Camel 2.4:</b> Whether or not this Exchange is the last. </td>
</tr>
</tbody></table>
</div>


<h3><a name="Splitter-Examples"></a>Examples</h3>

<p>The following example shows how to take a request from the <b>queue:a</b> endpoint the split it into pieces using an <a href="/confluence/display/CAMEL/Expression" title="Expression">Expression</a>, then forward each piece to <b>queue:b</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">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">"direct:a"</span>)
            .split(body(<span class="code-object">String</span>.class).tokenize(<span class="code-quote">"\n"</span>))
                .to(<span class="code-quote">"direct:b"</span>);
    }
};
</pre>
</div></div>

<p>The splitter can use any <a href="/confluence/display/CAMEL/Expression" title="Expression">Expression</a> language so you could use any of the <a href="/confluence/display/CAMEL/Languages+Supported" title="Languages Supported">Languages Supported</a> such as <a href="/confluence/display/CAMEL/XPath" title="XPath">XPath</a>, <a href="/confluence/display/CAMEL/XQuery" title="XQuery">XQuery</a>, <a href="/confluence/display/CAMEL/SQL" title="SQL">SQL</a> or one of the <a href="/confluence/display/CAMEL/Scripting+Languages" title="Scripting Languages">Scripting Languages</a> to perform the split. e.g.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"activemq:my.queue"</span>).split(xpath(<span class="code-quote">"<span class="code-comment">//foo/bar"</span>)).convertBodyTo(<span class="code-object">String</span>.class).to(<span class="code-quote">"file://some/directory"</span>)</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">"direct:a"</span>/&gt;</span>
        <span class="code-tag">&lt;split&gt;</span>
            <span class="code-tag">&lt;xpath&gt;</span>/invoice/lineItems<span class="code-tag">&lt;/xpath&gt;</span>
            <span class="code-tag">&lt;to uri=<span class="code-quote">"direct:b"</span>/&gt;</span>
        <span class="code-tag">&lt;/split&gt;</span>
    <span class="code-tag">&lt;/route&gt;</span>
<span class="code-tag">&lt;/camelContext&gt;</span>
</pre>
</div></div>

<p>For further examples of this pattern in use you could look at one of the <a href="http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/SplitterTest.java?view=markup" class="external-link" rel="nofollow">junit test case</a></p>

<h3><a name="Splitter-UsingTokenizerfromSpringXMLExtensions"></a>Using Tokenizer from <a href="/confluence/display/CAMEL/Spring+XML+Extensions" title="Spring XML Extensions">Spring XML Extensions</a>*</h3>
<p><b>Avaiaible as of Camel 2.0</b></p>

<p>You can use the tokenizer expression in the Spring DSL to split bodies or headers using a token. This is a common use-case, so we provided a special <b>tokenizer</b> tag for this.<br/>
In the sample below we split the body using a @ as separator. You can of course use comma or space or even a regex pattern, also set regex=true.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml"><span class="code-tag">&lt;camelContext 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">"direct:start"</span>/&gt;</span>
        <span class="code-tag">&lt;split&gt;</span>
            <span class="code-tag">&lt;tokenize token=<span class="code-quote">"@"</span>/&gt;</span>
            <span class="code-tag">&lt;to uri=<span class="code-quote">"mock:result"</span>/&gt;</span>
        <span class="code-tag">&lt;/split&gt;</span>
    <span class="code-tag">&lt;/route&gt;</span>
<span class="code-tag">&lt;/camelContext&gt;</span>
</pre>
</div></div>

<p>Splitting the body in Spring XML is a bit harder as you need to use the <a href="/confluence/display/CAMEL/Simple" title="Simple">Simple</a> language to dictate this</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;split&gt;</span>
   <span class="code-tag">&lt;simple&gt;</span>${body}<span class="code-tag">&lt;/simple&gt;</span>
   <span class="code-tag">&lt;to uri=<span class="code-quote">"mock:result"</span>/&gt;</span>
<span class="code-tag">&lt;/split&gt;</span>
</pre>
</div></div>

<h3><a name="Splitter-WhattheSplitterreturns"></a>What the Splitter returns</h3>
<p><b>Camel 2.2 or older:</b><br/>
The <a href="/confluence/display/CAMEL/Splitter" title="Splitter">Splitter</a> will by default return the <b>last</b> splitted message.</p>

<p><b>Camel 2.3 and newer</b><br/>
The <a href="/confluence/display/CAMEL/Splitter" title="Splitter">Splitter</a> will by default return the original input message.</p>

<p><b>For all versions</b><br/>
You can override this by suppling your own strategy as an <tt>AggregationStrategy</tt>. There is a sample on this page (Split aggregate request/reply sample). Notice its the same strategy as the <a href="/confluence/display/CAMEL/Aggregator" title="Aggregator">Aggregator</a> supports. This <a href="/confluence/display/CAMEL/Splitter" title="Splitter">Splitter</a> can be viewed as having a build in light weight <a href="/confluence/display/CAMEL/Aggregator" title="Aggregator">Aggregator</a>.</p>

<h3><a name="Splitter-Parallelexecutionofdistinct%27parts%27"></a>Parallel execution of distinct 'parts'</h3>
<p>If you want to execute all parts in parallel you can use special notation of <tt>split()</tt> with two arguments, where the second one is a <b>boolean</b> flag if processing should be parallel. e.g.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
XPathBuilder xPathBuilder = <span class="code-keyword">new</span> XPathBuilder(<span class="code-quote">"<span class="code-comment">//foo/bar"</span>); 
</span>from(<span class="code-quote">"activemq:my.queue"</span>).split(xPathBuilder, <span class="code-keyword">true</span>).to(<span class="code-quote">"activemq:my.parts"</span>);
</pre>
</div></div>

<p>In <b>Camel 2.0</b> the boolean option has been refactored into a builder method <tt>parallelProcessing</tt> so its easier to understand what the route does when we use a method instead of true|false.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
XPathBuilder xPathBuilder = <span class="code-keyword">new</span> XPathBuilder(<span class="code-quote">"<span class="code-comment">//foo/bar"</span>); 
</span>from(<span class="code-quote">"activemq:my.queue"</span>).split(xPathBuilder).parallelProcessing().to(<span class="code-quote">"activemq:my.parts"</span>);
</pre>
</div></div>

<h3><a name="Splitter-Streambased"></a>Stream based</h3>
<div class='panelMacro'><table class='infoMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/information.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Splitting big XML payloads</b><br />The XPath engine in Java and <a href="/confluence/display/CAMEL/XQuery" title="XQuery">saxon</a> will load the entire XML content into memory. And thus they are not well suited for very big XML payloads.<br/>
Instead you can use a custom <a href="/confluence/display/CAMEL/Expression" title="Expression">Expression</a> which will iterate the XML payload in a streamed fashion. From Camel 2.9 onwards you can use the Tokenizer language<br/>
which supports this when you supply the start and end tokens.</td></tr></table></div>

<p>You can split streams by enabling the streaming mode using the <tt>streaming</tt> builder method.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
    from(<span class="code-quote">"direct:streaming"</span>).split(body().tokenize(<span class="code-quote">","</span>)).streaming().to(<span class="code-quote">"activemq:my.parts"</span>);
</pre>
</div></div>

<p>You can also supply your custom splitter to use with streaming like this:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-keyword">import</span> <span class="code-keyword">static</span> org.apache.camel.builder.ExpressionBuilder.beanExpression;
from(<span class="code-quote">"direct:streaming"</span>)
     .split(beanExpression(<span class="code-keyword">new</span> MyCustomIteratorFactory(),  <span class="code-quote">"iterator"</span>))
     .streaming().to(<span class="code-quote">"activemq:my.parts"</span>)
</pre>
</div></div>

<h4><a name="Splitter-StreamingbigXMLpayloadsusingTokenizerlanguage"></a>Streaming big XML payloads using Tokenizer language</h4>
<p><b>Available as of Camel 2.9</b><br/>
If you have a big XML payload, from a file source, and want to split it in streaming mode, then you can use the Tokenizer language with start/end tokens to do this with low memory footprint.</p>

<div class='panelMacro'><table class='tipMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/check.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>StAX component</b><br />The Camel <a href="/confluence/display/CAMEL/StAX" title="StAX">StAX</a> component can also be used to split big XML files in a streaming mode. See more details at <a href="/confluence/display/CAMEL/StAX" title="StAX">StAX</a>.</td></tr></table></div>

<p>For example you may have a XML payload structured as follows</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;orders&gt;</span>
  <span class="code-tag">&lt;order&gt;</span>
    <span class="code-tag"><span class="code-comment">&lt;!-- order stuff here --&gt;</span></span>
  <span class="code-tag">&lt;/order&gt;</span>
  <span class="code-tag">&lt;order&gt;</span>
    <span class="code-tag"><span class="code-comment">&lt;!-- order stuff here --&gt;</span></span>
  <span class="code-tag">&lt;/order&gt;</span>
...
  <span class="code-tag">&lt;order&gt;</span>
    <span class="code-tag"><span class="code-comment">&lt;!-- order stuff here --&gt;</span></span>
  <span class="code-tag">&lt;/order&gt;</span>
<span class="code-tag">&lt;/orders&gt;</span>
</pre>
</div></div>

<p>Now to split this big file using <a href="/confluence/display/CAMEL/XPath" title="XPath">XPath</a> would cause the entire content to be loaded into memory. So instead we can use the Tokenizer language to do this as follows:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
  from(<span class="code-quote">"file:inbox"</span>)
    .split().tokenizeXML(<span class="code-quote">"order"</span>).streaming()
       .to(<span class="code-quote">"activemq:queue:order"</span>);
</pre>
</div></div>

<p>In XML DSL the route would be 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">"file:inbox"</span>/&gt;</span>
  <span class="code-tag">&lt;split streaming=<span class="code-quote">"true"</span>&gt;</span>
    <span class="code-tag">&lt;tokenize token=<span class="code-quote">"order"</span> xml=<span class="code-quote">"true"</span>/&gt;</span>
    <span class="code-tag">&lt;to uri=<span class="code-quote">"activemq:queue:order"</span>/&gt;</span>
  <span class="code-tag">&lt;/split&gt;</span>
<span class="code-tag">&lt;/route&gt;</span>
</pre>
</div></div>

<p>Notice the <tt>tokenizeXML</tt> method which will split the file using the tag name of the child node, which mean it will grab the content between the <tt>&lt;order&gt;</tt> and <tt>&lt;/order&gt;</tt> tags (incl. the tokens). So for example a splitted message would be as follows:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
  <span class="code-tag">&lt;order&gt;</span>
    <span class="code-tag"><span class="code-comment">&lt;!-- order stuff here --&gt;</span></span>
  <span class="code-tag">&lt;/order&gt;</span>
</pre>
</div></div>

<p>If you want to inherit namespaces from a root/parent tag, then you can do this as well by providing the name of the root/parent tag:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;route&gt;</span>
  <span class="code-tag">&lt;from uri=<span class="code-quote">"file:inbox"</span>/&gt;</span>
  <span class="code-tag">&lt;split streaming=<span class="code-quote">"true"</span>&gt;</span>
    <span class="code-tag">&lt;tokenize token=<span class="code-quote">"order"</span> inheritNamespaceTagName=<span class="code-quote">"orders"</span> xml=<span class="code-quote">"true"</span>/&gt;</span>
    <span class="code-tag">&lt;to uri=<span class="code-quote">"activemq:queue:order"</span>/&gt;</span>
  <span class="code-tag">&lt;/split&gt;</span>
<span class="code-tag">&lt;/route&gt;</span>
</pre>
</div></div>

<p>And in Java DSL its as follows:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
  from(<span class="code-quote">"file:inbox"</span>)
    .split().tokenizeXML(<span class="code-quote">"order"</span>, <span class="code-quote">"orders"</span>).streaming()
       .to(<span class="code-quote">"activemq:queue:order"</span>);
</pre>
</div></div>


<h4><a name="Splitter-SplittingfilesbygroupingNlinestogether"></a>Splitting files by grouping N lines together</h4>
<p><b>Available as of Camel 2.10</b></p>

<p>The <a href="/confluence/display/CAMEL/Tokenizer" title="Tokenizer">Tokenizer</a> language has a new option <tt>group</tt> that allows you to group N parts together, for example to split big files into chunks of 1000 lines.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
  from(<span class="code-quote">"file:inbox"</span>)
    .split().tokenize(<span class="code-quote">"\n"</span>, 1000).streaming()
       .to(<span class="code-quote">"activemq:queue:order"</span>);
</pre>
</div></div>

<p>And in XML DSL</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;route&gt;</span>
  <span class="code-tag">&lt;from uri=<span class="code-quote">"file:inbox"</span>/&gt;</span>
  <span class="code-tag">&lt;split streaming=<span class="code-quote">"true"</span>&gt;</span>
    <span class="code-tag">&lt;tokenize token=<span class="code-quote">"\n"</span> group=<span class="code-quote">"1000"</span>/&gt;</span>
    <span class="code-tag">&lt;to uri=<span class="code-quote">"activemq:queue:order"</span>/&gt;</span>
  <span class="code-tag">&lt;/split&gt;</span>
<span class="code-tag">&lt;/route&gt;</span>
</pre>
</div></div>

<p>The <tt>group</tt> option is a number that must be a positive number that dictates how many groups to combine together. Each part will be combined using the token.<br/>
So in the example above the message being sent to the activemq order queue, will contain 1000 lines, and each line separated by the token (which is a new line token).<br/>
The output when using the <tt>group</tt> option is always a <tt>java.lang.String</tt> type. </p>



<h4><a name="Splitter-Specifyingacustomaggregationstrategy"></a>Specifying a custom aggregation strategy </h4>
<p><b>Available as of Camel 2.0</b></p>

<p>This is specified similar to the <a href="/confluence/display/CAMEL/Aggregator" title="Aggregator">Aggregator</a>.</p>

<h4><a name="Splitter-SpecifyingacustomThreadPoolExecutor"></a>Specifying a custom ThreadPoolExecutor</h4>
<p>You can customize the underlying ThreadPoolExecutor used in the parallel splitter. In the Java DSL try something like this:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
XPathBuilder xPathBuilder = <span class="code-keyword">new</span> XPathBuilder(<span class="code-quote">"<span class="code-comment">//foo/bar"</span>); 
</span>
ExecutorService pool = ...

from(<span class="code-quote">"activemq:my.queue"</span>)
    .split(xPathBuilder).parallelProcessing().executorService(pool)
        .to(<span class="code-quote">"activemq:my.parts"</span>);
</pre>
</div></div>

<h4><a name="Splitter-UsingaPojotodothesplitting"></a>Using a Pojo to do the splitting</h4>
<p>As the <a href="/confluence/display/CAMEL/Splitter" title="Splitter">Splitter</a> can use any <a href="/confluence/display/CAMEL/Expression" title="Expression">Expression</a> to do the actual splitting we leverage this fact and use a <b>method</b> expression to invoke a <a href="/confluence/display/CAMEL/Bean" title="Bean">Bean</a> to get the splitted parts.<br/>
The <a href="/confluence/display/CAMEL/Bean" title="Bean">Bean</a> should return a value that is iterable such as: <tt>java.util.Collection, java.util.Iterator</tt> or an array. <br/>
So the returned value, will then be used by Camel at runtime, to split the message. </p>

<div class='panelMacro'><table class='tipMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/check.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Streaming mode and using pojo</b><br />When you have enabled the streaming mode, then you should return a <tt>Iterator</tt> to ensure streamish fashion. For example if the message is a big file, then by using an iterator, that returns a piece of the file in chunks, in the <tt>next</tt> method of the <tt>Iterator</tt> ensures low memory footprint. This avoids the need for reading the entire content into memory. For an example see the source code for the <a href="https://svn.apache.org/repos/asf/camel/trunk/camel-core/src/main/java/org/apache/camel/support/TokenPairExpressionIterator.java" class="external-link" rel="nofollow">TokenizePair</a> implementation.</td></tr></table></div>

<p>In the route we define the <a href="/confluence/display/CAMEL/Expression" title="Expression">Expression</a> as a method call to invoke our <a href="/confluence/display/CAMEL/Bean" title="Bean">Bean</a> that we have registered with the id mySplitterBean in the <a href="/confluence/display/CAMEL/Registry" title="Registry">Registry</a>.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">from(<span class="code-quote">"direct:body"</span>)
        <span class="code-comment">// here we use a POJO bean mySplitterBean to <span class="code-keyword">do</span> the split of the payload
</span>        .split().method(<span class="code-quote">"mySplitterBean"</span>, <span class="code-quote">"splitBody"</span>)
        .to(<span class="code-quote">"mock:result"</span>);
from(<span class="code-quote">"direct:message"</span>)
        <span class="code-comment">// here we use a POJO bean mySplitterBean to <span class="code-keyword">do</span> the split of the message 
</span>        <span class="code-comment">// with a certain header value
</span>        .split().method(<span class="code-quote">"mySplitterBean"</span>, <span class="code-quote">"splitMessage"</span>)
        .to(<span class="code-quote">"mock:result"</span>);
</pre>
</div></div>

<p>And the logic for our <a href="/confluence/display/CAMEL/Bean" title="Bean">Bean</a> is as simple as. Notice we use Camel <a href="/confluence/display/CAMEL/Bean+Binding" title="Bean Binding">Bean Binding</a> to pass in the message body as a String object. </p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java"><span class="code-keyword">public</span> class MySplitterBean {

    /**
     * The split body method returns something that is iteratable such as a java.util.List.
     *
     * @param body the payload of the incoming message
     * @<span class="code-keyword">return</span> a list containing each part splitted
     */
    <span class="code-keyword">public</span> List&lt;<span class="code-object">String</span>&gt; splitBody(<span class="code-object">String</span> body) {
        <span class="code-comment">// since <span class="code-keyword">this</span> is based on an unit test you can of cause
</span>        <span class="code-comment">// use different logic <span class="code-keyword">for</span> splitting as Camel have out
</span>        <span class="code-comment">// of the box support <span class="code-keyword">for</span> splitting a <span class="code-object">String</span> based on comma
</span>        <span class="code-comment">// but <span class="code-keyword">this</span> is <span class="code-keyword">for</span> show and tell, since <span class="code-keyword">this</span> is java code
</span>        <span class="code-comment">// you have the full power how you like to split your messages
</span>        List&lt;<span class="code-object">String</span>&gt; answer = <span class="code-keyword">new</span> ArrayList&lt;<span class="code-object">String</span>&gt;();
        <span class="code-object">String</span>[] parts = body.split(<span class="code-quote">","</span>);
        <span class="code-keyword">for</span> (<span class="code-object">String</span> part : parts) {
            answer.add(part);
        }
        <span class="code-keyword">return</span> answer;
    }
    
    /**
     * The split message method returns something that is iteratable such as a java.util.List.
     *
     * @param header the header of the incoming message with the name user
     * @param body the payload of the incoming message
     * @<span class="code-keyword">return</span> a list containing each part splitted
     */
    <span class="code-keyword">public</span> List&lt;Message&gt; splitMessage(@Header(value = <span class="code-quote">"user"</span>) <span class="code-object">String</span> header, @Body <span class="code-object">String</span> body) {
        <span class="code-comment">// we can leverage the Parameter Binding Annotations  
</span>        <span class="code-comment">// http://camel.apache.org/parameter-binding-annotations.html
</span>        <span class="code-comment">// to access the message header and body at same time, 
</span>        <span class="code-comment">// then create the message that we want, splitter will
</span>        <span class="code-comment">// take care <span class="code-keyword">rest</span> of them.
</span>        <span class="code-comment">// *NOTE* <span class="code-keyword">this</span> feature requires Camel version &gt;= 1.6.1
</span>        List&lt;Message&gt; answer = <span class="code-keyword">new</span> ArrayList&lt;Message&gt;();
        <span class="code-object">String</span>[] parts = header.split(<span class="code-quote">","</span>);
        <span class="code-keyword">for</span> (<span class="code-object">String</span> part : parts) {
            DefaultMessage message = <span class="code-keyword">new</span> DefaultMessage();
            message.setHeader(<span class="code-quote">"user"</span>, part);
            message.setBody(body);
            answer.add(message);
        }
        <span class="code-keyword">return</span> answer;
    }
}
</pre>
</div></div>

<h4><a name="Splitter-Splitaggregaterequest%2Freplysample"></a>Split aggregate request/reply sample</h4>
<p>This sample shows how you can split an <a href="/confluence/display/CAMEL/Exchange" title="Exchange">Exchange</a>, process each splitted message, aggregate and return a combined response to the original caller using request/reply.</p>

<p>The route below illustrates this and how the split supports a <b>aggregationStrategy</b> to hold the in progress processed messages:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java"><span class="code-comment">// <span class="code-keyword">this</span> routes starts from the direct:start endpoint
</span><span class="code-comment">// the body is then splitted based on @ separator
</span><span class="code-comment">// the splitter in Camel supports InOut as well and <span class="code-keyword">for</span> that we need
</span><span class="code-comment">// to be able to aggregate what response we need to send back, so we provide our
</span><span class="code-comment">// own strategy with the class MyOrderStrategy.
</span>from(<span class="code-quote">"direct:start"</span>)
    .split(body().tokenize(<span class="code-quote">"@"</span>), <span class="code-keyword">new</span> MyOrderStrategy())
        <span class="code-comment">// each splitted message is then send to <span class="code-keyword">this</span> bean where we can process it
</span>        .to(<span class="code-quote">"bean:MyOrderService?method=handleOrder"</span>)
        <span class="code-comment">// <span class="code-keyword">this</span> is important to end the splitter route as we <span class="code-keyword">do</span> not want to <span class="code-keyword">do</span> more routing
</span>        <span class="code-comment">// on each splitted message
</span>    .end()
    <span class="code-comment">// after we have splitted and handled each message we want to send a single combined
</span>    <span class="code-comment">// response back to the original caller, so we let <span class="code-keyword">this</span> bean build it <span class="code-keyword">for</span> us
</span>    <span class="code-comment">// <span class="code-keyword">this</span> bean will receive the result of the aggregate strategy: MyOrderStrategy
</span>    .to(<span class="code-quote">"bean:MyOrderService?method=buildCombinedResponse"</span>)
</pre>
</div></div>

<p>And the OrderService bean is as follows:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java"><span class="code-keyword">public</span> <span class="code-keyword">static</span> class MyOrderService {

    <span class="code-keyword">private</span> <span class="code-keyword">static</span> <span class="code-object">int</span> counter;

    /**
     * We just handle the order by returning a id line <span class="code-keyword">for</span> the order
     */
    <span class="code-keyword">public</span> <span class="code-object">String</span> handleOrder(<span class="code-object">String</span> line) {
        LOG.debug(<span class="code-quote">"HandleOrder: "</span> + line);
        <span class="code-keyword">return</span> <span class="code-quote">"(id="</span> + ++counter + <span class="code-quote">",item="</span> + line + <span class="code-quote">")"</span>;
    }

    /**
     * We use the same bean <span class="code-keyword">for</span> building the combined response to send
     * back to the original caller
     */
    <span class="code-keyword">public</span> <span class="code-object">String</span> buildCombinedResponse(<span class="code-object">String</span> line) {
        LOG.debug(<span class="code-quote">"BuildCombinedResponse: "</span> + line);
        <span class="code-keyword">return</span> <span class="code-quote">"Response["</span> + line + <span class="code-quote">"]"</span>;
    }
}
</pre>
</div></div>

<p>And our custom <b>aggregationStrategy</b> that is responsible for holding the in progress aggregated message that after the splitter is ended will be sent to the <b>buildCombinedResponse</b> method for final processing before the combined response can be returned to the waiting caller.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">/**
 * This is our own order aggregation strategy where we can control
 * how each splitted message should be combined. As we <span class="code-keyword">do</span> not want to
 * loos any message we copy from the <span class="code-keyword">new</span> to the old to preserve the
 * order lines as <span class="code-object">long</span> we process them
 */
<span class="code-keyword">public</span> <span class="code-keyword">static</span> class MyOrderStrategy <span class="code-keyword">implements</span> AggregationStrategy {

    <span class="code-keyword">public</span> Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
        <span class="code-comment">// put order together in old exchange by adding the order from <span class="code-keyword">new</span> exchange
</span>
        <span class="code-keyword">if</span> (oldExchange == <span class="code-keyword">null</span>) {
            <span class="code-comment">// the first time we aggregate we only have the <span class="code-keyword">new</span> exchange,
</span>            <span class="code-comment">// so we just <span class="code-keyword">return</span> it
</span>            <span class="code-keyword">return</span> newExchange;
        }

        <span class="code-object">String</span> orders = oldExchange.getIn().getBody(<span class="code-object">String</span>.class);
        <span class="code-object">String</span> newLine = newExchange.getIn().getBody(<span class="code-object">String</span>.class);

        LOG.debug(<span class="code-quote">"Aggregate old orders: "</span> + orders);
        LOG.debug(<span class="code-quote">"Aggregate <span class="code-keyword">new</span> order: "</span> + newLine);

        <span class="code-comment">// put orders together separating by semi colon
</span>        orders = orders + <span class="code-quote">";"</span> + newLine;
        <span class="code-comment">// put combined order back on old to preserve it
</span>        oldExchange.getIn().setBody(orders);

        <span class="code-comment">// <span class="code-keyword">return</span> old as <span class="code-keyword">this</span> is the one that has all the orders gathered until now
</span>        <span class="code-keyword">return</span> oldExchange;
    }
}
</pre>
</div></div>

<p>So lets run the sample and see how it works.<br/>
We send an <a href="/confluence/display/CAMEL/Exchange" title="Exchange">Exchange</a> to the <b>direct:start</b> endpoint containing a IN body with the String value: <tt>A&#64;B&#64;C</tt>. The flow is:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
HandleOrder: A
HandleOrder: B
Aggregate old orders: (id=1,item=A)
Aggregate <span class="code-keyword">new</span> order: (id=2,item=B)
HandleOrder: C
Aggregate old orders: (id=1,item=A);(id=2,item=B)
Aggregate <span class="code-keyword">new</span> order: (id=3,item=C)
BuildCombinedResponse: (id=1,item=A);(id=2,item=B);(id=3,item=C)
Response to caller: Response[(id=1,item=A);(id=2,item=B);(id=3,item=C)]
</pre>
</div></div>

<h3><a name="Splitter-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/Splitter" title="Splitter">Splitter</a> will by default continue to process the entire <a href="/confluence/display/CAMEL/Exchange" title="Exchange">Exchange</a> even in case of one of the splitted message will thrown an exception during routing.<br/>
For example if you have an <a href="/confluence/display/CAMEL/Exchange" title="Exchange">Exchange</a> with 1000 rows that you split and route each sub message. During processing of these sub messages an exception is thrown at the 17th. What Camel does by default is to process the remainder 983 messages. 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>)
        .split(body().tokenize(<span class="code-quote">","</span>)).stopOnException()
            .process(<span class="code-keyword">new</span> MyProcessor())
            .to(<span class="code-quote">"mock:split"</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;split stopOnException=<span class="code-quote">"true"</span>&gt;</span>
                <span class="code-tag">&lt;tokenize token=<span class="code-quote">","</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:split"</span>/&gt;</span>
            <span class="code-tag">&lt;/split&gt;</span>
        <span class="code-tag">&lt;/route&gt;</span>
</pre>
</div></div>

<h3><a name="Splitter-UsingonPreparetoexecutecustomlogicwhenpreparingmessages"></a>Using onPrepare to execute custom logic when preparing messages</h3>
<p><b>Available as of Camel 2.8</b></p>

<p>See details at <a href="/confluence/display/CAMEL/Multicast" title="Multicast">Multicast</a></p>


<h3><a name="Splitter-Sharingunitofwork"></a>Sharing unit of work</h3>
<p><b>Available as of Camel 2.8</b></p>

<p>The <a href="/confluence/display/CAMEL/Splitter" title="Splitter">Splitter</a> will by default not share unit of work between the parent exchange and each splitted exchange. This means each sub exchange has its own individual unit of work.</p>

<p>For example you may have an use case, where you want to split a big message. And you want to regard that process as an atomic isolated operation that either is a success or failure. In case of a failure you want that big message to be moved into a <a href="/confluence/display/CAMEL/Dead+Letter+Channel" title="Dead Letter Channel">dead letter queue</a>. To support this use case, you would have to share the unit of work on the <a href="/confluence/display/CAMEL/Splitter" title="Splitter">Splitter</a>.</p>

<p>Here is an example in Java DSL</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">errorHandler(deadLetterChannel(<span class="code-quote">"mock:dead"</span>).useOriginalMessage()
        .maximumRedeliveries(3).redeliveryDelay(0));

from(<span class="code-quote">"direct:start"</span>)
    .to(<span class="code-quote">"mock:a"</span>)
    <span class="code-comment">// share unit of work in the splitter, which tells Camel to propagate failures from
</span>    <span class="code-comment">// processing the splitted messages back to the result of the splitter, which allows
</span>    <span class="code-comment">// it to act as a combined unit of work
</span>    .split(body().tokenize(<span class="code-quote">","</span>)).shareUnitOfWork()
        .to(<span class="code-quote">"mock:b"</span>)
        .to(<span class="code-quote">"direct:line"</span>)
    .end()
    .to(<span class="code-quote">"mock:result"</span>);

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

<p>Now in this example what would happen is that in case there is a problem processing each sub message, the error handler will kick in (yes error handling still applies for the sub messages). <b>But</b> what doesn't happen is that if a sub message fails all redelivery attempts (its exhausted), then its <b>not</b> moved into that dead letter queue. The reason is that we have shared the unit of work, so the sub message will report the error on the shared unit of work. When the <a href="/confluence/display/CAMEL/Splitter" title="Splitter">Splitter</a> is done, it checks the state of the shared unit of work and checks if any errors occurred. And if an error occurred it will set the exception on the <a href="/confluence/display/CAMEL/Exchange" title="Exchange">Exchange</a> and mark it for rollback. The error handler will yet again kick in, as the <a href="/confluence/display/CAMEL/Exchange" title="Exchange">Exchange</a> has been marked as rollback and it had an exception as well. No redelivery attempts is performed (as it was marked for rollback) and the <a href="/confluence/display/CAMEL/Exchange" title="Exchange">Exchange</a> will be moved into the <a href="/confluence/display/CAMEL/Dead+Letter+Channel" title="Dead Letter Channel">dead letter queue</a>.</p>

<p>Using this from XML DSL is just as easy as you just have to set the shareUnitOfWork attribute to true:</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">"dlc"</span> xmlns=<span class="code-quote">"http://camel.apache.org/schema/spring"</span>&gt;</span>

  <span class="code-tag"><span class="code-comment">&lt;!-- define error handler as DLC, with use original message enabled --&gt;</span></span>
  <span class="code-tag">&lt;errorHandler id=<span class="code-quote">"dlc"</span> type=<span class="code-quote">"DeadLetterChannel"</span> deadLetterUri=<span class="code-quote">"mock:dead"</span> useOriginalMessage=<span class="code-quote">"true"</span>&gt;</span>
    <span class="code-tag">&lt;redeliveryPolicy maximumRedeliveries=<span class="code-quote">"3"</span> redeliveryDelay=<span class="code-quote">"0"</span>/&gt;</span>
  <span class="code-tag">&lt;/errorHandler&gt;</span>

  <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;to uri=<span class="code-quote">"mock:a"</span>/&gt;</span>
    &lt;!-- share unit of work in the splitter, which tells Camel to propagate failures from
         processing the splitted messages back to the result of the splitter, which allows
         it to act as a combined unit of work --&gt;
    <span class="code-tag">&lt;split shareUnitOfWork=<span class="code-quote">"true"</span>&gt;</span>
      <span class="code-tag">&lt;tokenize token=<span class="code-quote">","</span>/&gt;</span>
      <span class="code-tag">&lt;to uri=<span class="code-quote">"mock:b"</span>/&gt;</span>
      <span class="code-tag">&lt;to uri=<span class="code-quote">"direct:line"</span>/&gt;</span>
    <span class="code-tag">&lt;/split&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"><span class="code-comment">&lt;!-- route for processing each splitted line --&gt;</span></span>
  <span class="code-tag">&lt;route&gt;</span>
    <span class="code-tag">&lt;from uri=<span class="code-quote">"direct:line"</span>/&gt;</span>
    <span class="code-tag">&lt;to uri=<span class="code-quote">"log:line"</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:line"</span>/&gt;</span>
  <span class="code-tag">&lt;/route&gt;</span>

<span class="code-tag">&lt;/camelContext&gt;</span>
</pre>
</div></div>

<div class='panelMacro'><table class='infoMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/information.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Implementation of shared unit of work in Camel 2.x</b><br />The Camel team had to introduce a <tt>SubUnitOfWork</tt> to keep API compatible with the current <tt>UnitOfWork</tt> in Camel 2.x code base. So in reality the unit of work is not shared as a single object instance. Instead <tt>SubUnitOfWork</tt> is attached to their parent, and issues callback to the parent about their status (commit or rollback). This may be refactored in Camel 3.0 where larger API changes can be done.</td></tr></table></div>

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

Mime
View raw message