您好我很新,春天尝试使用SFTP入站通道适配器从sftp服务器获取文件,但无法关闭适配器,我尝试使用下面的代码片段,但Main不会重新启动入站适配器和所以adapter.start()和adapter.stop();不工作。请提供关闭InboundChannelAdapter的任何工作示例。
public SftpInboundFileSynchronizer sftpInboundFileSynchronizer() {
SftpInboundFileSynchronizer fileSynchronizer = new SftpInboundFileSynchronizer(sftpSessionFactory());
fileSynchronizer.setDeleteRemoteFiles(false);
fileSynchronizer.setRemoteDirectory(sftpFolder);
fileSynchronizer.setFilter(new SftpSimplePatternFileListFilter("*.pdf"));
return fileSynchronizer;
}
@Bean
@InboundChannelAdapter(channel = "stream",poller = @Poller(fixedDelay ="5000",maxMessagesPerPoll = "1"),autoStartup="false")
public MessageSource<File> sftpMessageSource() {
SftpInboundFileSynchronizingMessageSource source = new SftpInboundFileSynchronizingMessageSource(
sftpInboundFileSynchronizer());
source.setLocalDirectory(new File("ftp-inbound"));
source.setAutoCreateLocalDirectory(true);
source.setLocalFilter(new AcceptOnceFileListFilter<File>());
return source;
}
@Bean
@Transformer(inputChannel = "stream", outputChannel = "data")
public org.springframework.integration.transformer.Transformer transformer() {
return new StreamTransformer();
}
@Bean
@ServiceActivator(inputChannel = "stream")
public MessageHandler handler() {
return new MessageHandler() {
@Override
public void handleMessage(Message<?> message) throws MessagingException {
System.out.println("payload"+ message.getPayload());
//System.out.println(""+message.);
}
};
}
@Bean
@ServiceActivator(inputChannel = "controlBusChannel")
public ExpressionControlBusFactoryBean controlBus() throws Exception {
ExpressionControlBusFactoryBean controlBus = new ExpressionControlBusFactoryBean();
return controlBus;
}