gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 19:57:03 24 4
gpt4 key购买 nike

我正在研究 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com