我编写了一个代码,用于将csv文件从一个文件夹传输到另一个文件夹,并在传输时移除最后一列,但在运行时,完成会在控制台上多次出现但路由工作正常。这是由于Apache camel的线程模型分配多线程?
from("file:///home/Laptop/Desktop/java/DemoFeed/1?
antInclude=*.gz&move=processed").unmarshal().gzip().process(new
Processor() {
public void process(Exchange exchange) throws Exception
StringBuilder builder = new StringBuilder();
String body=exchange.getIn().getBody(String.class);
String row[]=body.split("\n");
for(int rowIndex=0;rowIndex<row.length-1;rowIndex++)
{
String rowIterator=row[rowIndex];
String rowEntries[]=rowIterator.split(",");
for(int index=0;index<rowEntries.length-1;index++)
{
builder.append(rowEntries[index]);
if(index!=rowEntries.length-2)
builder.append(",");
}
builder.append("\n");
exchange.getOut().setBody(builder.toString());
System.out.println("done");
}
}
}).setHeader(Exchange.FILE_NAME,constant("name.csv")).marshal().zipFile().to("file:2?fileName=name.csv.zip");
答案 0 :(得分:0)
正如@ james-netherton已经评论过的那样:只需要两行
exchange.getOut().setBody(builder.toString());
System.out.println("done");
外部for循环。您覆盖邮件正文并在每个已处理的行后打印done
。