【问题标题】:How could I transfer message from my File Inbound adapter to Sftp Outbound adapter through Spring DSL in java 1.7如何通过 java 1.7 中的 Spring DSL 将消息从我的文件入站适配器传输到 Sftp 出站适配器
【发布时间】:2015-07-23 10:34:06
【问题描述】:

我如何通过 java 1.7 中的 Spring DSL 将消息从我的文件入站适配器传输到 Sftp 出站适配器,因为我有两个用于文件入站适配器和 Sftp 出站适配器的单独流,但我无法从 Sftp 出站发送消息适配器虽然我的入站适配器工作正常。 我想做这样的事情......但我正在努力将这件事转换为我的集成流程。

消息消息 = 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();
}

【问题讨论】:

  • 这似乎是 your other question 的副本。只需将两个流与同一通道连接在一起即可。你还有什么不明白的?
  • 嗨,加里,很抱歉我的愚蠢问题,但实际上我无法正确地将两个流连接在一起。正如您上次告诉我需要在我的流程中添加一个“PublishSubscribeChannel”,而这一点我无法继续并且真的很挣扎。我还在另一个问题中分享了我的新流程。那么您能否在该流程中提及如何使用它。
  • 需要 pub/sub 通道,因为您想在 sftp 传输之后做一些事情 - 这次您根本没有提及。如果您只想检测文件并传输它,只需将上述流程连接在一起即可。请更详细地说明您要解决的问题。
  • 嗨,Gary,是的,我需要查找本地目录中的所有文件,并通过 Sftp OutBound 适配器将这些文件传输到远程目录。这就是我写了两个流程的原因,一个是文件入站,它检测本地目录中的文件,另一个是 Sftp 出站流,它将这些文件传输到远程目录。上面发布的两个流程工作正常,但我无法将这两个流程正确连接在一起。 Sftp 出站传输成功后,我不需要任何东西。

标签: spring-integration


【解决方案1】:

您不需要将文件读入内存; 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()) 开始第二个。

【讨论】:

  • 嗨,加里,非常感谢您的回答............它也解决了我的问题,现在我能够理解如何将两个流连接在一起。跨度>
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-26
  • 1970-01-01
  • 1970-01-01
  • 2020-12-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多