无法使用SFTP流入站适配器读取文件

时间:2019-07-27 06:38:41

标签: spring-integration spring-integration-sftp

我想从远程主机读取文件并进行处理。我尝试了spring-integration文档中提供的文件读取示例,但是它不起作用。 我不想下载文件。应用将在PCF上运行,我不确定如何提供在PCF中本地存储文件的路径。这就是为什么我使用流适配器 有人可以告诉我我做错了吗

Spring Boot ::(v2.2.0.BUILD-SNAPSHOT)

@SpringBootApplication
public class SprintIntgerationDemoApplication {

    public static void main(String[] args) {        
        new SpringApplicationBuilder(SprintIntgerationDemoApplication.class)
        .web(WebApplicationType.NONE)
        .run(args);
    }

}

@Configuration
@EnableIntegration
class FtpConfiguration{

    @Bean
    SessionFactory<LsEntry> ftpFileSessionfactory(@Value("${ftp.host}") String host, 
                                                    @Value("${ftp.port}") int port, 
                                                    @Value("${ftp.user}") String user, 
                                                    @Value("${ftp.password}") String password) {
        DefaultSftpSessionFactory defaultSftpSessionFactory = new DefaultSftpSessionFactory();
        defaultSftpSessionFactory.setHost(host);
        defaultSftpSessionFactory.setPort(port);
        defaultSftpSessionFactory.setUser(user);
        defaultSftpSessionFactory.setPassword(password);
        return  new CachingSessionFactory<>(defaultSftpSessionFactory);
    }

        @Bean
        @InboundChannelAdapter(channel = "stream",poller= @Poller(cron="0 5 12 * * *"))
        public MessageSource<InputStream> ftpMessageSource(SftpRemoteFileTemplate template,@Value("${ftp.sourcePath}") String path) {
            SftpStreamingMessageSource messageSource = new SftpStreamingMessageSource(template);
            messageSource.setRemoteDirectory(path+"/");
            messageSource.setFilter(new ExpressionFileListFilter<LsEntry>("user*csv"));
            messageSource.setMaxFetchSize(1);
            return messageSource;
        }

        @Bean
        @Transformer(inputChannel = "stream", outputChannel = "data")
        public org.springframework.integration.transformer.Transformer transformer() {
            return new StreamTransformer("UTF-8");
        }

        @Bean
        public SftpRemoteFileTemplate template(SessionFactory<LsEntry> ftpFileSessionfactory) {
            return new SftpRemoteFileTemplate(ftpFileSessionfactory);
        }

        @ServiceActivator(inputChannel = "data")
        @Bean
        public MessageHandler handle() {
             return System.out::println;
        }
}

我希望可以打印一些文件名或其内容,但是建立连接后什么也没发生。请参阅下面的日志片段

2019-07-27 12:03:34.869  INFO 19384 --- [  restartedMain] c.a.s.d.SprintIntgerationDemoApplication : Started SprintIntgerationDemoApplication in 0.318 seconds (JVM running for 61940.703)
2019-07-27 12:03:34.869  INFO 19384 --- [  restartedMain] .ConditionEvaluationDeltaLoggingListener : Condition evaluation unchanged
2019-07-27 12:05:00.001  INFO 19384 --- [ask-scheduler-1] com.jcraft.jsch                          : Connecting to ***** 21
2019-07-27 12:05:00.316  INFO 19384 --- [ask-scheduler-1] com.jcraft.jsch                          : Connection established

0 个答案:

没有答案