I would like to do the following with spring integration
- Fetch files from sftp
- Send the downloaded files to http and also to s3
Here is what I have so far.
@Bean
@InboundChannelAdapter(channel = "sftpChannel", poller = @Poller(fixedDelay = "100000", maxMessagesPerPoll = "3"))
public MessageSource<File> sftpMessageSource() {
SftpInboundFileSynchronizingMessageSource source = new SftpInboundFileSynchronizingMessageSource(sftpInboundFileSynchronizer());
source.setLocalDirectory(new File("sftp-inbound"));
source.setAutoCreateLocalDirectory(true);
source.setMaxFetchSize(2);
return source;
}
Here is my service activator. The problem with my service activator is this run in the same thread as the poller, so when the file process too long, it doesn't process the next until the first one is done.
@ServiceActivator(inputChannel = "sftpChannel")
public void sftpChannel(@Payload File payload, @Header("timestamp") long timestamp) {
log.info("Message arrived at sftpChannel");
//do something with file
}
How can I run the file process on separate thread and release the poller thread instead, so the poller can continue to pull files from sftp?
@PollertakestaskExecutorwhich you can configure to run asynchronously. - tsolakpThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); executor.setMaxPoolSize(5);for example:pool.execute(() -> process(payload, timestamp), 1000);Do you have a sample? - user311633