Reputation: 86687
I want to download a file from ftp server periodically (only when the file has changed). Therefore I'd like to use Spring-Integration
4.0.
What is the annotation based configuration equivalent of the following setup with int-ftp
?
<int-ftp:inbound-channel-adapter id="ftpInbound"
channel="ftpChannel"
session-factory="ftpClientFactory"
filename-pattern="*.txt"
auto-create-local-directory="true"
delete-remote-files="false"
remote-directory="/">
<int:poller fixed-rate="1000"/>
</int-ftp:inbound-channel-adapter>
I started with the following, but don't know how I can configure the channel with its attributes like session-factory
, remote-directory
etc.
@Configuration
@EnableIntegration
public class Application {
@Bean
public SessionFactory<FTPFile> sessionFactory() {
DefaultFtpSessionFactory ftp = new DefaultFtpSessionFactory();
ftp.setHost("ftp.test");
ftp.setPort(21);
ftp.setUsername("anonymous");
ftp.setPassword("anonymous");
return ftp;
}
@InboundChannelAdapter(value = "ftpChannel", poller = @Poller(fixedDelay = "1000", maxMessagesPerPoll = "1"))
public String connect() {
// return the ftp file
}
@ServiceActivator(inputChannel = "ftpChannel")
public void foo(String payload) {
System.out.println("paylod: " + payload);
}
}
Upvotes: 1
Views: 3921
Reputation: 174514
The (S)FTP inbound adapters are on the more complex side; we're working in the DSL to make this easier but, currently, you need an @Bean FtpInboundFileSynchronizer
wired up with appropriate properties and inject it into
Then
@Bean
@InboundChannelAdapter(value = "ftpChannel", poller = @Poller(fixedDelay = "1000", maxMessagesPerPoll = "1"))
public MessageSource receive() {
FtpInboundFileSynchronizingMessageSource messageSource = new FtpInboundFileSynchronizingMessageSource(synchronizer());
...
return messageSource;
}
Upvotes: 3