0

我正在创建一个文件传输路径,move用于设置文件传输成功后移动文件的动态路径。我还设置了一个通知程序来跟踪文件传输事件。

由于移动路径是动态的,我需要获取文件传输后文件移动的评估路径。这个路径怎么能在notifier里面呢?

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;
    }
}
4

2 回答 2

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);
    }

}
于 2017-01-10T08:55:55.767 回答
0

您可以尝试向交易所添加标头,例如:

.setHeader("FILE_PROCESSED").simple("存档/${date:now:yyyyMMdd}/${file:onlyname}")

于 2015-12-15T17:26:49.443 回答