我想定期从ftp服务器下载文件(仅当文件发生变化时)。因此,我想使用Spring-Integration
4.0。
基于注释的配置与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>
我从以下开始,但不知道如何使用session-factory
,remote-directory
等属性配置频道。
@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);
}
}
答案 0 :(得分:3)
(S)FTP入站适配器位于更复杂的一侧;我们在DSL中工作以使这更容易,但是,目前,您需要@Bean FtpInboundFileSynchronizer
连接适当的属性并将其注入
然后
@Bean
@InboundChannelAdapter(value = "ftpChannel", poller = @Poller(fixedDelay = "1000", maxMessagesPerPoll = "1"))
public MessageSource receive() {
FtpInboundFileSynchronizingMessageSource messageSource = new FtpInboundFileSynchronizingMessageSource(synchronizer());
...
return messageSource;
}