我正在创建一个文件传输路由,它使用move
来设置成功传输文件后文件移动的动态路径。我还设置了一个通知程序来跟踪文件传输事件。
由于移动路径是动态的,我需要获取文件传输后文件移动的评估路径。如何在通知程序中使用此路径?
public class MyFtpServiceBuilder extends RouteBuilder {
@Override
public void configure() throws Exception {
getContext()
.getManagementStrategy()
.addEventNotifier(new MyFtpServiceNotifier());
from("file:C:/tmp/inputfolder?move=archive/${date:now:yyyyMMdd}/${file:onlyname}")
.routeId("myRoute")
.to("file:C:/tmp/outputfolder")
}
}
public class MyFtpServiceNotifier extends EventNotifierSupport {
@Override
public void notify(EventObject event) throws Exception {
Exchange exchange = ((AbstractExchangeEvent) event).getExchange();
if (event instanceof ExchangeSentEvent) {
// Want to get here the path where file was moved
}
}
@Override
public boolean isEnabled(EventObject event) {
return event instanceof AbstractExchangeEvent;
}
}
答案 0 :(得分:0)
您可以尝试在交易所添加标题,例如:
.setHeader(" FILE_PROCESSED&#34)简单。("存档/ $ {日期:现在:YYYYMMDD} / $ {文件:onlyname}&#34)
答案 1 :(得分:0)
我不确定如何在通知程序中执行此操作,但您始终可以添加处理器并在交换机上使用FileEndpoint.getMove().evaluate()
方法来获取最终移动的文件路径。
例如:
@Override
public void process(final Exchange exchange) throws Exception {
File movedFile = null;
if (exchange.getFromEndpoint() instanceof FileEndpoint) {
FileEndpoint fileEndpoint = (FileEndpoint) exchange.getFromEndpoint();
String movePath = fileEndpoint.getMove().evaluate(exchange, String.class);
File inputDir = fileEndpoint.getFile();
movedFile = new File(inputDir, movePath);
}
}