При использовании адаптера потокового входящего канала SFTP кажется, что сеанс не закрыт. Когда адаптер исчерпывает сеанс, доступный на сервере sftp, тогда Spring генерирует исключение com.jcraft.jsch.JSchException.
Когда RemoteFileTemplate
выполняет ls на сервере, я вижу, что он открывает и закрывает сеанс,однако, когда AbstractRemoteFileStreamingMessageSource
выполняет doReceive
, я не вижу никакого вызова, чтобы закрыть сеанс. Это, вероятно, неправильная конфигурация с моей стороны.
вот ниже моя конфигурация:
@Bean
public SessionFactory<ChannelSftp.LsEntry> sftpSessionFactory() {
DefaultSftpSessionFactory factory = new DefaultSftpSessionFactory(true);
factory.setHost(properties.getHost());
factory.setPort(properties.getPort());
factory.setUser(properties.getUsername());
factory.setPassword(properties.getPassword());
CachingSessionFactory cachingSessionFactory = new CachingSessionFactory<>(factory);
return cachingSessionFactory;
}
@Bean
public SftpRemoteFileTemplate template() {
return new SftpRemoteFileTemplate(sftpSessionFactory());
}
@Bean
@InboundChannelAdapter(channel = "sftpChannel", poller = @Poller(cron = "0/5 * * * * *", maxMessagesPerPoll = "10"))
public MessageSource<InputStream> sftpMessageSource(ConcurrentMetadataStore concurrentMetadataStore) {
ChainFileListFilter<ChannelSftp.LsEntry> filterChain = new ChainFileListFilter<>();
if (properties.getFilterPattern() != null && !"".equals(properties.getFilterPattern()))
filterChain.addFilter(new SftpRegexPatternFileListFilter(properties.getFilterPattern()));
filterChain.addFilter(new SftpPersistentAcceptOnceFileListFilter(concurrentMetadataStore, "sftpSource"));
SftpStreamingMessageSource messageSource = new SftpStreamingMessageSource(template());
messageSource.setRemoteDirectory(properties.getRemoteDirectory());
messageSource.setFilter(filterChain);
return messageSource;
}
@Bean
@ServiceActivator(inputChannel = "sftpChannel")
public MessageHandler handler(SftpDocumentInput sftpDocumentInput) {
return sftpDocumentInput;
}
Спасибо за вашу помощь!