【发布时间】:2014-03-04 04:51:56
【问题描述】:
阿帕奇骆驼路线:
from("file:/tmp/test?include=.*.csv").process(new Processor() {
public void process(Exchange exchange) throws Exception {
// set output file name
exchange.setProperty("outputFile", exchange.getIn().getHeader(Exchange.FILE_NAME, String.class) + ".tmp." + exchange.getExchangeId());
}
}).onCompletion().split().tokenize("\n", 100).process(new RequestProcessor()).to("direct:response").end().process(new Processor() {
public void process(Exchange exchange) throws Exception {
final String outputFile = exchange.getProperty("outputFile", String.class);
// add new rout to encrypt
CamelContext context = new DefaultCamelContext();
context.addRoutes(new RouteBuilder() {
public void configure() {
from("file:/tmp/test/output?fileName=" + outputFile).marshal().pgp(keyFileName, keyUserid).to("file:/tmp/test/output?fileName=" + outputFile + ".pgp");
}
});
context.start();
Thread.sleep(5000);
context.stop();
}
});
from("direct:response").to("file:/tmp/test/output?fileName=${header.outputFile}&fileExist=Append");
上面的路线正在处理大文件拆分成块(用于批处理)并生成带有结果的输出文件。一旦生成了我需要加密的输出文件。所以我在 onCompletion 文件拆分/处理路由的处理器内添加了新路由。它可以工作,但我觉得这不是一个好的设计(因为涉及两个上下文并且需要明确关闭上下文)。
谁能建议我触发加密路线的正确方法。
【问题讨论】:
标签: java apache-camel