Apache Camel Seda Route仍然会修改我的主要路线体

时间:2018-03-15 09:46:19

标签: java apache-camel

我正在使用Camel路线。该路径将sftp中的一个目录中的CSV文件带到sftp内的另一个目录,同时执行到XML的转换。

from(mySftp.getUri("/camel"))
   .choice()
       .when(body().isNull())
           .log("No Files Found")
       .otherwise()
           .process(new Processor() {
                StringBuilder sb = new StringBuilder();
                public void process(Exchange exchange) throws Exception {
                String body =  exchange.getIn().getBody(String.class).toString();
                String [] lines = body.split("\n");
                for(String line : lines) {
                      String [] fields = line.split(",");
                      //trasformation here
                }
                exchange.setProperty("generatedXml", sb.toString());
                }
}).to(mySftp.getUri("/camel/archive"))

这非常合适,直到我调用seda route我已经定义了它的目的是通过设置正文和所需的标题来发送SNS。

代码如下。

from("seda:sendSNS")
.setBody().simple("message")
.setHeader("CamelAwsSnsSubject", simple("subject"))
.to(myInfoSns.getUri());

这就是我通过使用"来调用我的seda route"

 from(mySftp.getUri("/camel"))
   .to("seda:sendSNS")
   .choice()
       .when(body().isNull())
           .log("No Files Found")
       .otherwise()
           .process(new Processor() {
                StringBuilder sb = new StringBuilder();
                public void process(Exchange exchange) throws Exception {
                String body =  exchange.getIn().getBody(String.class).toString();
                String [] lines = body.split("\n");
                for(String line : lines) {
                      String [] fields = line.split(",");
                      //trasformation here
                }
                exchange.setProperty("generatedXml", sb.toString());
                }
}).to(mySftp.getUri("/camel/archive"))

我期待虽然我正在呼唤seda路线并将其身体设置在内部,但这不应该影响我的主要路线。看起来我的XML生成成功但是我的主路径无法将文件移动到所需的目标。

我得到的错误是

Exhausted after delivery attempt: 1 caught: org.apache.camel.component.file.GenericFileOperationFailedException: Cannot store file: camel/archive/file.csv

No body available of type: java.io.InputStream but has value: RemoteFile[file.csv] of type: org.apache.camel.component.file.remote.RemoteFile on: file.csv. Caused by: Error during type conversion from type: java.lang.String to the required type: java.io.InputStream with value [Body is file based: \tmp\file.csv] due \tmp\file.csv (The system cannot find the file specified). Exchange[ID-IT1289-1521106847220-0-1]. Caused by: [org.apache.camel.TypeConversionException - Error during type conversion from type: java.lang.String to the required type: java.io.InputStream with value [Body is file based: \tmp\file.csv] due \tmp\file.csv (The system cannot find the file specified)]

任何想法可能是什么原因造成的?调用seda route "sendSNS"后,为什么我的文件找不到。

1 个答案:

答案 0 :(得分:3)

您的目的是将邮件的副本发送到seda端点,因此您需要的集成是wireTap

from(mySftp.getUri("/camel"))
  .wireTap("seda:sendSNS")
  .choice()
  //the rest...

相关文档为here

  

Wire Tap(来自EIP模式)允许您在将消息转发到最终目的地时将消息路由到单独的位置。