I have UC where I need to pick the files from ftp location and place it into the server location I am using ftp-inbound-channel-adapter (Spring integration - 2.0.4) for achi
That log only shows 4 files; it looks like it was configured for 3 messages per poll and it clearly shows 3 files were sent at 12:38 and 1 and 12:40 (with no fifth file found).
Poll resulted in Message: null
EDIT
Here is another way to achieve your desired result (using outbound gateways). This version uses the Java DSL.
If you prefer to use XML configuration, a similar flow is provided (in XML) in the ftp-sample - you would have to insert the file limiter between the ls
gateway and splitter.
@SpringBootApplication
public class So42528316Application {
public static void main(String[] args) throws Exception {
ConfigurableApplicationContext context = SpringApplication.run(So42528316Application.class, args);
try {
context.getBean(So42528316Application.class).runDemo();
}
finally {
context.close();
}
}
@Autowired
private FileGateway fetchAndProcess;
private void runDemo() throws Exception {
Collection<Boolean> rmResults = this.fetchAndProcess.processFilesAt("so42528316");
while (rmResults != null) {
System.out.println("Processed " + rmResults.size() + " files");
Thread.sleep(10_000);
rmResults = this.fetchAndProcess.processFilesAt("so42528316");
}
System.out.println("No more files available");
}
@MessagingGateway(defaultRequestChannel = "flow.input", defaultReplyTimeout = "0")
public interface FileGateway {
Collection<Boolean> processFilesAt(String pattern);
}
@Bean
public DefaultFtpSessionFactory sessionFactory() {
DefaultFtpSessionFactory factory = new DefaultFtpSessionFactory();
factory.setHost("10.0.0.3");
factory.setUsername("ftptest");
factory.setPassword("ftptest");
factory.setClientMode(FTPClient.PASSIVE_LOCAL_DATA_CONNECTION_MODE);
return factory;
}
@Bean
public IntegrationFlow flow() {
return f -> f
.handle(Ftp.outboundGateway(sessionFactory(), "ls", "payload"))
.handle("so42528316Application", "limitFiles")
.split()
.handle(Ftp.outboundGateway(sessionFactory(), "get",
"payload.remoteDirectory + '/' + payload.filename")
.localDirectory(new File("/tmp", "so42528316")))
.handle("so42528316Application", "process")
.handle(Ftp.outboundGateway(sessionFactory(), "rm",
"headers['file_remoteDirectory'] + '/' + headers['file_remoteFile']"))
.aggregate();
}
public List<FtpFileInfo> limitFiles(List<FtpFileInfo> files) {
// Add any logic you want here, e.g. check if file already on local disk.
if (files.size() == 0) {
return null;
}
else if (files.size() > 2) {
System.out.println("Reducing fetch list from " + files.size() + " to 2");
return files.stream().limit(2).collect(Collectors.toList());
}
else {
return files;
}
}
public String process(File file) {
System.out.println("Processing " + file);
file.delete();
return file.getName();
}
}
Result:
Reducing fetch list from 3 to 2
Processing /tmp/so42528316/bar.txt
Processing /tmp/so42528316/baz.txt
Processed 2 files
Processing /tmp/so42528316/foo.txt
Processed 1 files
No more files available