-
1. Re: Scatter / Gatter Pattern using Camel
janstey Dec 11, 2008 9:38 PM (in response to mggardiner)I just put in an example of this pattern at http://svn.apache.org/repos/asf/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/ScatterGatherTest.java
Feedback is welcome as I was just utilizing stuff already available in Camel. So, it may be possible to make this much nicer in future releases.
For your usecase, a standard splitter will do http://activemq.apache.org/camel/splitter.html and for the parallel multicast bit, see this testcase http://svn.apache.org/repos/asf/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/MultiCastAggregatorTest.java
Let me know if you need anymore help.
Cheers,
Jon
Edited by: janstey on Dec 11, 2008 11:08 PM
-
2. Re: Scatter / Gatter Pattern using Camel
mggardiner Dec 11, 2008 3:56 PM (in response to janstey)Thanks for the example Jon. I did have another question of how to insert the combined bodies back into the original root elements. For example:
If I had the following
root
root
I get the stuff elements split out sent out fine but in the aggregation strategy I get the stuff elements back with more information for my use case but I want to have the stuff elements embedded back into the root element. What is the proper way of doing this?
By the way I am not using DSL but Spring XML to perform the pattern.
Thanks.
Edited by: mggardiner on Dec 11, 2008 3:50 PM
Edited by: mggardiner on Dec 11, 2008 3:53 PM
Edited by: mggardiner on Dec 11, 2008 3:55 PM
Edited by: mggardiner on Dec 11, 2008 3:55 PM
-
3. Re: Scatter / Gatter Pattern using Camel
mggardiner Dec 11, 2008 3:58 PM (in response to mggardiner)The body of the message is like the following only real elements
root
stuff
stuff
root
Edited by: mggardiner on Dec 11, 2008 3:58 PM
-
4. Re: Scatter / Gatter Pattern using Camel
janstey Dec 11, 2008 9:36 PM (in response to mggardiner)If you require that the new data be inserted into the original XML document you could just add it as a header
<setHeader headerName="theOriginalDocument"> <simple>body</simple> </setHeader>
so when the message arrives in your custom aggregator you would have the original document, which you can manipulate any way you please.
public Exchange aggregate(Exchange oldExchange, Exchange newExchange) { Object theDocument = oldExchange.getIn().getHeader("theOriginalDocument"); ...
Of course, this is a bad idea if in your route you use endpoints that access resources outside the local VM (JMS, HTTP, etc.) as these would need to serialize the entire original document for each split message. Of course, it works fine in the local VM cause there is only one reference to the same object...
If this is the case for you, you'll need to either: (1) create a new document from scratch, or (2) save the original to somewhere where you can access it again.
Hope this helps.
Cheers.
-
5. Re: Scatter / Gatter Pattern using Camel
janstey Feb 2, 2009 3:22 PM (in response to janstey)FYI
I put together a better example of the Scatter-Gather pattern on the Apache Camel wiki
http://cwiki.apache.org/confluence/display/CAMEL/Scatter-Gather
Cheers,
Jon