我如何通过 java 1.7 中的 Spring DSL 将消息从我的文件入站适配器传输到 Sftp 出站适配器
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 出站适配器,因为我有两个单独的文件入站适配器和 Sftp 出站适配器流,但我尽管我的 InBound 适配器工作正常,但无法从 Sftp Outbound 适配器发送消息。
我想做这样的事情......但我正在努力将它转换为我的集成流程。
留言留言=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();
}
您不需要将文件读入内存; 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())
开始。
我如何在 java 1.7 中通过 Spring DSL 将消息从我的文件入站适配器传输到 Sftp 出站适配器,因为我有两个单独的文件入站适配器和 Sftp 出站适配器流,但我尽管我的 InBound 适配器工作正常,但无法从 Sftp Outbound 适配器发送消息。 我想做这样的事情......但我正在努力将它转换为我的集成流程。
留言留言=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();
}
您不需要将文件读入内存; 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())
开始。