我想在Java中编写一个骆驼路径,它经常检查文件夹中的文件,然后将它们发送到处理器。
我知道,我这样做对我来说很“肮脏”:
from( "file:C:\\exampleSource" ).process( new Processor()
{
@Override
public void process( Exchange msg )
{
File file = msg.getIn().getBody( File.class );
Filecheck( file );
}
} );
}
} );
camelContext.start();
while ( true )
{
// run
}是否有更好的方法来实现这一点?
提前谢谢。
发布于 2015-02-09 13:04:47
还可以将文件处理移动到专用类:
import java.io.File;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
public class FileProcessor implements Processor {
@Override
public void process(Exchange exchange) throws Exception {
File file = exchange.getIn().getBody(File.class);
processFile(file);
}
private void processFile(File file) {
//TODO process file
}
}然后按以下方式使用:
from("file:C:\\exampleSource").process(new FileProcessor());看看可用的骆驼maven原型:camel-archetype-java反映您的情况的http://camel.apache.org/camel-maven-archetypes.html
发布于 2015-02-09 12:46:26
下面是一种更干净的方法:
public static void main(String[] args) throws Exception {
Main camelMain = new Main();
camelMain.addRouteBuilder(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("file:C:\\xyz")
// do whatever
;
}
});
camelMain.run();
}https://stackoverflow.com/questions/28410100
复制相似问题