首页 文章

如何通过Java 1.7中的Spring DSL将消息从我的文件入站适配器传输到Sftp出站适配器

提问于
浏览
1

我如何通过Spring 1.7中的Spring DSL将消息从我的文件入站适配器传输到Sftp出站适配器,因为我有两个用于文件入站适配器和Sftp出站适配器的separtae流程,但是我无法通过Sftp出站适配器发送消息InBound适配器工作正常 . 我想做一些这样的事情......但是我正在努力将这个东西转换成我的整合流程 .

消息message = this.fileReadingResultChannel.receive();
this.toSftpChannel.send(消息);

有人可以帮助我,因为我坚持在这里,无法继续 .

我的文件入站流程看起来像这样..

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

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

@Bean
public MessageSource<File> fileMessageSource() {

    FileReadingMessageSource source = new FileReadingMessageSource();
    source.setDirectory(new File(localDir));    
    source.setAutoCreateDirectory(true);        
    return source;
}

这是我的sftp出站流程..

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

1 回答

  • 0

    您不需要将文件读入内存; sftp适配器将读取并直接发送 .

    @Bean
    public IntegrationFlow transferFlow() {
        return IntegrationFlows.from(Files.inboundAdapter(new File("/tmp/foo")),
                    new Consumer<SourcePollingChannelAdapterSpec>() {
    
                        @Override
                        public void accept(SourcePollingChannelAdapterSpec e) {
                            e
                            .autoStartup(true)
                            .poller(Pollers
                                .fixedDelay(5000)
                                .maxMessagesPerPoll(1));
                        }
                    })
                .handle(Sftp.outboundAdapter(this.sftpSessionFactory)
                        .useTemporaryFileName(false)
                        .remoteDirectory("destDir"))
                .get();
    }
    

    如果你想将它保存为2个独立的流,只需将它们与通道bean连接:

    @Bean
    public MessageChannel foo() {
        return new DirectChannel();
    }
    

    .channel(foo()) 结束第一个并用 .from(foo()) 开始第二个 .

相关问题