I have created a route that
Question: How to print multiple files on basis of number of arrays generated by aggregator?
from("file:C:\\Users\\Desktop?fileName=books.xml&noop=true")
.split(xpath("/books/book"))
.process(new MyProcessor())
.setHeader("category", xpath("/book/@category").stringResult())
.aggregate(header("category"), new SetAggregationStrategy()).completionTimeout(500)
.process(new MyProcessor())
.convertBodyTo(String.class)
.to("file:C:\\Users\\Desktop\\New")
.end();
A strategy for aggregating two exchanges together into a single exchange.
The SEDA component provides asynchronous SEDA behavior, so that messages are exchanged on a BlockingQueue and consumers are invoked in a separate thread from the producer. Note that queues are only visible within a single CamelContext.
noop (consumer) If true, the file is not moved or deleted in any way. This option is good for readonly data, or for ETL type requirements. If noop=true, Camel will set idempotent=true as well, to avoid consuming the same files over and over again.
I think you just overwrite the same file with every new aggregation. To avoid this, you have to give every aggregation another (dynamic) filename to write it to.
For example to set [categoryname].xml as filename for every aggreation you can use
.setHeader(Exchange.FILE_NAME, simple("${headers.category}.xml"))
Exchange.FILE_NAME is a Camel constant for the filename header and with the Simple expression language you can concatenate the category name you set as header in your route and a static file suffix.
If the same category is aggregated over an over again, you have to extend the filename further (otherwise a category overwrites its previous file). For example with a timestamp or similar.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With