Hi,
Sorry if I spam ( I also speak in jira )
Hi,
( Sorry if I spam, I also speak in jira )
I have found a solution, based on the idea of send the exchange to both
endpoint :
public void configure() throws Exception {
// Properties
final String PROP_WRITE_IN_FILE_1 = "PROP_WRITE_IN_FILE_1";
final String PROP_WRITE_IN_FILE_2 = "PROP_WRITE_IN_FILE_2";
// Routes
final String ROUTE_FILE_1 = "direct:ROUTE_FILE_1" ;
final String ROUTE_FILE_2 = "direct:ROUTE_FILE_2" ;
// MAIN ROUTE
from("file://C:/Temp/camel/rep1/?noop=true")
.log("start process file => ${file:name}")
.split()
.tokenize("\n").streaming().process(new Processor() {
public void process(Exchange exchange) throws Exception {
// After 2 lines, next lines are rejected via an
// exchange property
i++;
if (i <= 2) {
exchange.setProperty(PROP_WRITE_IN_FILE_1, true);
exchange.setProperty(PROP_WRITE_IN_FILE_2, false);
} else {
exchange.setProperty(PROP_WRITE_IN_FILE_1, false);
exchange.setProperty(PROP_WRITE_IN_FILE_2, true);
}
}
})
.multicast().parallelProcessing()
.to(ROUTE_FILE_1 , ROUTE_FILE_2 )
.end()
.log("end process file => ${file:name}")
.end();
// OUT FILE 1
from(ROUTE_FILE_1)
.process(new Processor() {
public void process(Exchange exchange) throws Exception {
if( ! exchange.getProperty(PROP_WRITE_IN_FILE_1,
Boolean.class).booleanValue())
exchange.getIn().setBody(null);
}
})
.to("stream:file?fileName=C:/Temp/camel/rep1/out/out_1.csv&closeOnDone=true")
.end();
// OUT FILE 2
from( ROUTE_FILE_2)
.process(new Processor() {
public void process(Exchange exchange) throws Exception {
if( ! exchange.getProperty(PROP_WRITE_IN_FILE_2,
Boolean.class).booleanValue())
exchange.getIn().setBody(null);
}
})
.to("stream:file?fileName=C:/Temp/camel/rep1/out/out_2.csv&closeOnDone=true")
.end();
}
It complicate the process but it works...
For me camel doesn't manage correctly the Content Based Router from the EIP
patterns in the file:stream component