我正在编写DSL路由读取不同CSV文件的路由。 我正在基于标题过滤CSV并对其执行一些操作,如解组。 我的路线:
CsvDataFormat csv = new CsvDataFormat();
//Route 1 for filter CSV based on header
from("file:/home/r2/Desktop/csvFile?noop=true")
.choice().when(body().contains("partyName"))
.to("direct:partyNameCSV")
.when(body().contains("\"stuffName\""))
.to("direct:stuffNameCSV")
.otherwise().endChoice();
//Route 2 partyNameCSV
from("direct:partyNameCSV")
.unmarshal(csv)
.process(new PartyNameCSVProcessor())
.end();
//Route 3 stuffNameCSV
from("direct:stuffNameCSV")
.unmarshal(csv)
.process(new StuffCSVProcessor())
.end();
输出:构建成功但不调用任何处理器
[CSV.map.AutoCSV.main()] INFO org.apache.camel.impl.DefaultCamelContext - Route: route1 started and consuming from: file:///home/r2/Desktop/csvFile?noop=true
[CSV.map.AutoCSV.main()] INFO org.apache.camel.impl.DefaultCamelContext - Route: route2 started and consuming from: direct://partyNameCSV
[CSV.map.AutoCSV.main()] INFO org.apache.camel.impl.DefaultCamelContext - Route: route3 started and consuming from: direct://stuffNameCSV
[CSV.map.AutoCSV.main()] INFO org.apache.camel.impl.DefaultCamelContext - Total 3 routes, of which 3 are started
[CSV.map.AutoCSV.main()] INFO org.apache.camel.impl.DefaultCamelContext - Apache Camel 2.20.1 (CamelContext: camel-1) started in 0.638 seconds
[CSV.map.AutoCSV.main()] INFO org.apache.camel.impl.DefaultCamelContext - Apache Camel 2.20.1 (CamelContext: camel-1) is shutting down
[CSV.map.AutoCSV.main()] INFO org.apache.camel.impl.DefaultShutdownStrategy - Starting to graceful shutdown 3 routes (timeout 300 seconds)
[Camel (camel-1) thread #2 - ShutdownTask] INFO org.apache.camel.impl.DefaultShutdownStrategy - Route: route3 shutdown complete, was consuming from: direct://stuffNameCSV
[Camel (camel-1) thread #2 - ShutdownTask] INFO org.apache.camel.impl.DefaultShutdownStrategy - Route: route2 shutdown complete, was consuming from: direct://partyNameCSV
[Camel (camel-1) thread #2 - ShutdownTask] INFO org.apache.camel.impl.DefaultShutdownStrategy - Route: route1 shutdown complete, was consuming from: file:///home/r2/Desktop/csvFile?noop=true
我的问题是我做错了什么或者我错过了什么?
更新:
file1.csv
"partyName","partNumber"
"rajat temaniya","1"
"lalit kumar","2"
file2.csv
"stuffName","price"
"laptop","88000"
"mobile","50000"
答案 0 :(得分:0)
在进行任何基于内容的路由之前,使用convertBodyTo(String.class)
转换您的身体。
答案 1 :(得分:0)
您可以启用streamcache,以便保留正文供以后使用,并建议将邮件转换为字符串。
from({{consumer}})
.streamCaching()
.to({{producer}});