|
Splitter has been edited by Claus Ibsen (Jan 13, 2009). Content:SplitterThe Splitter As of Camel 2.0, you need to specify a Splitter as split(). In earlier versions of Camel, you need to use splitter(). ExampleThe following example shows how to take a request from the queue:a endpoint the split it into pieces using an _expression_, then forward each piece to queue:b Using the Fluent Builders RouteBuilder builder = new RouteBuilder() { public void configure() { from("seda:a").split(body(String.class).tokenize("\n")).to("seda:b"); } };
Parallel execution of distinct 'parts'If you want to execute all parts in parallel you can use special notation of split() with two arguments, where the second one is a boolean flag if processing should be parallel. e.g. XPathBuilder xPathBuilder = new XPathBuilder("//foo/bar"); from("activemq:my.queue").split(xPathBuilder, true).to("activemq:my.parts"); In Camel 2.0 the boolean option has been refactored into a builder method parallelProcessing so its easier to understand what the route does when we use a method instead of true|false. XPathBuilder xPathBuilder = new XPathBuilder("//foo/bar"); from("activemq:my.queue").split(xPathBuilder).parallelProcessing().to("activemq:my.parts"); Stream basedAvailable as of Camel 1.5 You can split streams by enabling the streaming mode using the streaming builder method. Specifying a custom aggregation strategyAvailable as of Camel 2.0 This is specified similar to the Aggregator. Specifying a custom ThreadPoolExecutorYou can customize the underlying ThreadPoolExecutor used in the parallel splitter. In the Java DSL try something like this: XPathBuilder xPathBuilder = new XPathBuilder("//foo/bar"); ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(8, 16, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue()); from("activemq:my.queue").split(xPathBuilder, true, threadPoolExecutor).to("activemq:my.parts"); In the Spring DSL try this: Available as of Camel 1.5.1 <camelContext id="camel" xmlns="http://activemq.apache.org/camel/schema/spring"> <route> <from uri="direct:parallel-custom-pool"/> <split threadPoolExecutorRef="threadPoolExecutor"> <xpath>/invoice/lineItems</xpath> <to uri="mock:result"/> </split> </route> </camelContext> <!-- There's an easier way of specifying constructor args, just can't remember it at the moment... old Spring syntax will do for now! --> <bean id="threadPoolExecutor" class="java.util.concurrent.ThreadPoolExecutor"> <constructor-arg index="0"><value>8</value></constructor-arg> <constructor-arg index="1"><value>16</value></constructor-arg> <constructor-arg index="2"><value>0</value></constructor-arg> <constructor-arg index="3"><value>MILLISECONDS</value></constructor-arg> <constructor-arg index="4"><bean class="java.util.concurrent.LinkedBlockingQueue"/></constructor-arg> </bean> Using This PatternIf you would like to use this EIP Pattern then please read the Getting Started, you may also find the Architecture useful particularly the description of Endpoint and URIs. Then you could try out some of the Examples first before trying this pattern out. |
Unsubscribe or edit your notifications preferences
