首页 文章

Spring集成DSL在java 1.7中创建Sftp OutBound适配器

提问于
浏览
1

我在Spring DSL中创建了一个Sftp出站流程,我还在Sftp出站流程上创建了一个文件入站流程,用于从我的本地目录查找文件并将其发送到消息通道,该通道负责将文件复制到远程目录,但是当我运行我的代码时,没有文件被复制到远程目录中 . 所以我在这一点上陷入困境,任何人都可以提供任何指针,因为我无法继续 .

这是我的 Session 工厂......

@Autowired
    private DefaultSftpSessionFactory sftpSessionFactory;

    @Bean
    public DefaultSftpSessionFactory sftpSessionFactory() {
        DefaultSftpSessionFactory factory = new DefaultSftpSessionFactory(
                true);
        factory.setHost("111.11.12.143");
        factory.setPort(22);
        factory.setUser("sftp");
        factory.setPassword("*******");         
        return factory;
    }

这是我的sftp出站流程..

@Bean
    public IntegrationFlow sftpOutboundFlow() {
        return IntegrationFlows
                .from("toSftpChannel")
                .handle(Sftp.outboundAdapter(this.sftpSessionFactory)
                        .remoteFileSeparator("\\")
                        .useTemporaryFileName(false)
                        .remoteDirectory(remDir)).get();
    }

这是我的文件入站流程..

@Bean
    public IntegrationFlow fileReadingFlow() {
        return IntegrationFlows
                .from(fileMessageSource(),
                         new Consumer<SourcePollingChannelAdapterSpec>() {

                    @Override
                    public void accept(SourcePollingChannelAdapterSpec e) {
                        e.poller(Pollers.fixedRate(6));
                    }
                })
                .transform(Transformers.fileToByteArray())
                .channel(MessageChannels.queue("fileReadingResultChannel"))
                .get();
    }

这个MessageSource方法.......

@Bean
    public MessageSource<File> fileMessageSource() {

        FileReadingMessageSource source = new FileReadingMessageSource();
        source.setDirectory(new File(localDir));
        source.setAutoCreateDirectory(true);
        System.out.println("enter fileMessageSource....."+ source.receive());
        return source;
    }

这是我的Junit测试方法......

@Autowired
private DefaultSftpSessionFactory sftpSessionFactory;

@Autowired
@Qualifier("toSftpChannel")
private MessageChannel toSftpChannel;

@Autowired  
@Qualifier("fileReadingResultChannel")
private PollableChannel fileReadingResultChannel;

@Test
public void testSftpOutboundFlow() {        
    Message<?> message = ((PollableChannel) fileReadingResultChannel)
            .receive(600);
    System.out.println("message....."+message);     
    this.toSftpChannel.send(message);       
}

1 回答

  • 0

    System.out.println("enter fileMessageSource....."+ source.receive());fileMessageSource() @Bean 中不好,只是因为你在那里 source.receive() . 这样做不是 SOUT 的责任 .

    从另一方面来看,如果你和我们分享一些关于此问题的StackTrace会更好......

    还有一点:你在控制台中看到了 System.out.println("message....."+message); 的结果吗?

相关问题