mike27
mike27

Reputation: 975

Apache camel using seda

I want to have a behavior like this: Camel reads a file from a directory, splits it into chunks (using streaming), sends each chunk to a seda queue for concurrent processing, and after the processing is done, a report generator is invoked. This is my camel route:

from("file://c:/mydir?move=.done")
.to("bean:firstBean")
.split(ExpressionBuilder.beanExpression("splitterBean", "split"))
.streaming()
.to("seda:processIt")
.end()
.to("bean:reportGenerator");

from("seda:processIt")
.to("bean:firstProcessingBean")
.to("bean:secondProcessingBean");

When I run this, the reportGenerator bean is run concurrently with the seda processing. How to make it run once after the whole seda processing is done?

Upvotes: 0

Views: 2165

Answers (2)

Claus Ibsen
Claus Ibsen

Reputation: 55545

The splitter has built-in parallel so you can do this easier as follows:

from("file://c:/mydir?move=.done")
  .to("bean:firstBean")
  .split(ExpressionBuilder.beanExpression("splitterBean", "split"))
  .streaming().parallelProcessing()
    .to("bean:firstProcessingBean")
    .to("bean:secondProcessingBean");
  .end()
  .to("bean:reportGenerator");

You can see more details about the parallel option at the Camel splitter page: http://camel.apache.org/splitter

Upvotes: 2

U2one
U2one

Reputation: 381

I think you can use the delayer pattern of Camel on the second route to achieve the purpose.

delay(long) in which the argument indicates time in milliseconds. You can read more abuout this pattern here

For eg; from("seda:processIt").delay(2000) .to("bean:firstProcessingBean"); //delays this route by 2 seconds

I'd suggest the usage of startupOrder to configure the startup of route though. The official documentation provides good details on the topic. Kindly read it here

Point to note - " The routes with the lowest startupOrder is started first. All startupOrder defined must be unique among all routes in your CamelContext."

So, I'd suggest something like this -

from("endpoint1").startupOrder(1)
.to("endpoint2");


from("endpoint2").startupOrder(2)
.to("endpoint3");

Hope that helps..

PS : I'm new to Apache Camel and to stackoverflow as well. Kindly pardon any mistake that might've occured.

Upvotes: 1

Related Questions