java - Apache Camel Seda Route 仍然修改我的主路由主体

标签 java apache-camel

我正在研究 Camel 路线。该路由将 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 路由,我已经定义了它的目的是通过设置正文和所需的 header 来发送 SNS。

代码如下。

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

这就是我使用“to”调用我的seda路线的方式

 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 路由“sendSNS” 后找不到我的文件。

最佳答案

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

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

相关文档为here :

Wire Tap (from the EIP patterns) allows you to route messages to a separate location while they are being forwarded to the ultimate destination.

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

相关文章:

java - 调试从 JAVA 程序调用的 MATLAB 函数

java - java中的继承私有(private)字段

java - LibGDX 按钮无法识别点击(Stage + ChangeListener)

java - JMS 异常 - 无法连接到代理 URL

java - Apache Camel 同步文件路由

java - 再次运行程序时如何让扫描仪暂停以进行输入?

java - 如何防止混淆\实现另一个方法的类方法名称?

apache-camel - Apache Camel 中的partition_key 与 key 的区别

java - 如果死信中重新传递失败,Camel 将消息存储在文件组件中

java - Camel : Add TypeConverter in Test Case