它可以使用 onException、try-catch-finally 或自定义文件处理策略进行归档,但它们都不是很方便。
我想出了这个简单的代码:
@Override
public void configure() throws Exception {
errorHandler(loggingErrorHandler(logger));
from("sftp://XXX@safsdf.de/dir/?delay=2s&move=${in.header.outDirectory}&moveFailed=failImport")
.process(exchange -> exchange.setProperty(originalMessage, exchange.getIn()))
.split()
.body()
.process(e -> {
String fileName = (String) e.getIn().getHeader(Exchange.FILE_NAME);
Message origMsg = (Message) e.getProperty(originalMessage);
try {
// do what ever
origMsg.setHeader(outDirectory, "done/" + fileName);
} catch (KaboomException ex) {
origMsg.setHeader(outDirectory, "retry/" + fileName);
}
})
.log("Imported file ${file:name} completely.");
}
在原始消息上设置标题很重要。