Reputation: 11
I am trying to pull file from a folder when a new file is created or modified. As per my current code its working when new file is created, but when i am adding same file with modified contents but that is not polling.
@Bean
public IntegrationFlow flow() {
return IntegrationFlows.from(
Files.inboundAdapter(new File(FOLDER)), e -> e.poller(Pollers.fixedDelay(10000)))
.transform(Transformers.objectToString())
.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) {
File file = message.getHeaders().get(FileHeaders.ORIGINAL_FILE, File.class);
try {
Object result = callback.execute();
String fileName=file.getName();
System.out.println("new file created");
return result;
}
catch (Exception e) {
System.out.println(e.getMessage());
}
return null;
}
};
}
public static class Processor {
public void process(String in) {
System.out.println(in);
}
}
Upvotes: 1
Views: 155
Reputation: 121542
The Files.inboundAdapter()
must be configured with the FileSystemPersistentAcceptOnceFileListFilter
which check for the lastmodified
, unlike an AcceptOnceFileListFilter
which is used by default.
See more about that in docs: https://docs.spring.io/spring-integration/reference/html/file.html#file-reading
Upvotes: 1