Kumar Ritesh
Kumar Ritesh

Reputation: 193

How do We pick 2 Files in a single route in Apache Camel, and process them simultaneously?

I have 2 files at the same file location..... I want both the files to be picked up at the same time, so that I can get hold of both in my Processor at the same time...

I am using Apache Camel for routing.

Upvotes: 1

Views: 1190

Answers (1)

Petter Nordlander
Petter Nordlander

Reputation: 22279

The solution to your problem depends a lot of the cirumstances.

If you can predict the file names you can easily use a pollEnrich together with an aggregation strategy.

The aggregation strategy gives you a method like this

Exchange aggregate(Exchange oldExchange,Exchange newExchange)

so that you can decide how to deal with the two files. oldExchange is the original exchange, newExchange will be the exchange from the enriching URI.

Pseudo code example:

from("file:inbox?fileName=invoices.csv")
  .pollEnrich("file:inbox2?fileName=customers.xml" strategyRef="myAggregationStrategy")
  .bean(someTransformerBean)
  .to("file:outbox?fileName=report.xml");

Upvotes: 3

Related Questions