[英]Spring integration - SFTP rename or move file in remote server after copying
[英]Spring integration move file after processing
處理文件..后如何在Spring集成中處理后移動文件? 我已按照http://xpadro.blogspot.com/2016/07/spring-integration-polling-file.html實施文件輪詢,但是我需要添加onSuccess和OnError跨國事件(無XML配置)
我不確定您所說的“交易”是什么意思,文件系統通常不是事務性的,但是您可以向流程中的最終使用者添加建議...
@SpringBootApplication
public class So40625031Application {
public static void main(String[] args) {
SpringApplication.run(So40625031Application.class, args);
}
@Bean
public IntegrationFlow flow() {
return IntegrationFlows.from(
Files.inboundAdapter(new File("/tmp/foo")), e -> e.poller(Pollers.fixedDelay(1000)))
.transform(Transformers.fileToString())
.handle("processor", "process", e -> e.advice(advice()))
.get();
}
@Bean
public Processor processor() {
return new Processor();
}
@Bean
public AbstractRequestHandlerAdvice advice() {
return new AbstractRequestHandlerAdvice() {
@Override
protected Object doInvoke(ExecutionCallback callback, Object target, Message<?> message) throws Exception {
File file = message.getHeaders().get(FileHeaders.ORIGINAL_FILE, File.class);
try {
Object result = callback.execute();
file.renameTo(new File("/tmp/bar", file.getName()));
System.out.println("File renamed after success");
return result;
}
catch (Exception e) {
file.renameTo(new File("/tmp/baz", file.getName()));
System.out.println("File renamed after failure");
throw e;
}
}
};
}
public static class Processor {
public void process(String in) {
System.out.println(in);
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.