How to split a message do some extra processing on one of them and aggregate them back
<p>I need to configure some camel routes based on some configuration files.</p>

<p>All configured routes will need to split a message into one or two sub messages then do some JMS integration work on the first one and then aggregate together the JMS reply with the optional second message. In a simplified picture it will look like below:</p>

<pre><code>message -- &gt; split  --&gt; message 1 --&gt; JMS request/reply --&gt; aggregate --&gt; more processing
                   \--&gt; message 2                      / 
</code></pre>

<p>The aggregation will be done on completion size which I am able to know upfront if it is going to be 1 or 2 depending of the route meta data. When the second message is present no other processing is needed before being merged back with the JMS reply.</p>

<p>Si in short I need a split followed by a routing followed by an aggregation which is quite a common pattern. The only particularity is is that in case the second split message is present I don't need to do anything on it before aggregating it back.</p>

<p>In java DSL it will looks something like this:</p>

<pre><code>from("direct:abc")
    // The splitter below  will set the JmsIntegration flag
    .split().method(MySplitter.class, "split")
    .choice()
        .when(header("JmsIntegration"))
            .inOut("jms:someQueue"))
        .otherwise()
            // what should I have on here?
            .to(???)
    .end()
    .aggregate(...)to(...);
</code></pre>

<p>So my questions would be:</p>

<ol>
<li><p>What should I put on the otherwise branch?</p>

<p>What I need in fact is an <code>if</code>: if the split message needs JMS go to JMS and then move to aggregator if it is not just go straight to the aggregator. I am considering creating a dummy processor which will actually do nothing but this seems to me a naive approach.</p></li>
<li><p>Am I on a wrong path. If so what would be the alternative</p>

<p>Initially I was thinking about a message enricher but I would not like to sent the original message to the JMS</p></li>
<li><p>I also considered putting my aggregation strategy inside my splitter but again I could not put it all together.</p></li>
</ol>