Apache camel Camel文件移动到目录而不是文件
我有一个文件路由,例如:Apache camel Camel文件移动到目录而不是文件,apache-camel,Apache Camel,我有一个文件路由,例如: from("file://" + inbox + "" + "?delay=1000" + "&preMove=/tmp/staging" + "&move=/tmp/processed") .bean(MyProcessor.class) .marshal(listJacksonDataFormat)
from("file://" + inbox + "" +
"?delay=1000" +
"&preMove=/tmp/staging" +
"&move=/tmp/processed")
.bean(MyProcessor.class)
.marshal(listJacksonDataFormat)
.to("restlet:http://localhost:58080/new-greeting?restletMethod=POST");
收件箱中给定的文件是:mycalc.xls
由于某种原因,在路由处理后,camel会将mycalc.xls
移动到名为/tmp/processed
的文件中,而不是将其移动到/tmp/processed/
目录中,并保留mycalc.xls
的原始文件名
编辑:
以下是我的简化MyProcessor类:
@Component
public class MyProcessor implements Processor {
@Override
public void process(Exchange exchange) throws Exception {
File file = exchange.getIn().getBody(File.class);
log.info("Processing file: " + file);
exchange.getOut().setBody("Hello World");
}
}
好的,我找到了问题行,它是:
exchange.getOut().setBody(“你好世界”)代码>
一接到电话,我就有了意想不到的行为 正如克劳斯所说,“move”和“preMove”选项通常需要目标文件名表达式,而不仅仅是目录名(但它可以与目录名一起工作,如“.done”)。因此,首先尝试将路线更改为:
from("file://" + inbox + "" +
"?delay=1000" +
"&preMove=/tmp/staging/${file:name}" +
"&move=/tmp/processed/${file:name}")
.bean(MyProcessor.class)
.marshal(listJacksonDataFormat)
.to("restlet:http://localhost:58080/new-greeting?restletMethod=POST");
正如Claus所提到的,“move”和“preMove”选项通常需要目标文件名表达式,而不仅仅是目录名(但它可以与目录名一起工作,如“.done”)。因此,首先尝试将路线更改为:
from("file://" + inbox + "" +
"?delay=1000" +
"&preMove=/tmp/staging/${file:name}" +
"&move=/tmp/processed/${file:name}")
.bean(MyProcessor.class)
.marshal(listJacksonDataFormat)
.to("restlet:http://localhost:58080/new-greeting?restletMethod=POST");
问题是我必须改变:exchange.getOut().setBody(“Hello World”)
toexchange.getIn().setBody(“Hello World”)代码>
据我所知,我错误地使用了In-Out(请求/应答)消息交换模式,在文件交换上显式地进行应答
这不是正确做法的原因如下:
a、 )一开始不需要这样做,因为默认情况下,Camel会沿着交换传递消息,而
b、 )通过使用getOut()
创建了一条新消息,该消息随后在以下Exchange上设置为IN,从而导致问题
有关更多信息,请参阅:问题是我必须更改:exchange.getOut().setBody(“Hello World”)
toexchange.getIn().setBody(“Hello World”)代码>
据我所知,我错误地使用了In-Out(请求/应答)消息交换模式,在文件交换上显式地进行应答
这不是正确做法的原因如下:
a、 )一开始不需要这样做,因为默认情况下,Camel会沿着交换传递消息,而
b、 )通过使用getOut()
创建了一条新消息,该消息随后在以下Exchange上设置为IN,从而导致问题
有关更多信息,请参阅:问题似乎与封送处理操作有关。如果我没有执行封送处理操作,它将按预期工作。我不确定是否理解,您的意思是mycalc.xls的内容被移动到名为“在tmp文件夹下处理”的文件中?您使用的是什么Camel版本和操作系统?子句:我尝试了Camel 2.15.3和Camel 2.16.1。两者的行为相同。在Linux上。其行为与执行命令mv/tmp/inbox/mycalc.xls/tmp/processed时完全相同,似乎问题与封送处理操作有关。如果我没有执行封送处理操作,它将按预期工作。我不确定是否理解,您的意思是mycalc.xls的内容被移动到名为“在tmp文件夹下处理”的文件中?您使用的是什么Camel版本和操作系统?子句:我尝试了Camel 2.15.3和Camel 2.16.1。两者的行为相同。在Linux上。它的行为与执行命令mv/tmp/inbox/mycalc.xls/tmp/processed时完全相同感谢您的建议,但没有什么不同感谢您的建议,但没有什么不同