我正在研究骆驼路线。该路径将CSV文件从sftp中的一个目录传送到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());


这就是我通过使用“ to”来调用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"后找不到文件。

最佳答案

您的意图是将消息的副本发送到seda端点,因此您需要的集成是wireTap

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


相关文档为here


  Wire Tap(来自EIP模式)使您可以在将邮件转发到最终目的地时将其路由到另一个位置。

关于java - Apache Camel Seda Route仍然修改了我的主要路线主体,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49296066/

10-10 11:59