我在spring DSL中创建了一个Sftp出站流,我还在Sftp出站流之上创建了一个文件入站流,用于从我的本地目录查找文件,并将其发送到负责将文件复制到远程目录的消息通道,但当我运行代码时,没有文件在远程目录中复制。所以我被困在这一点上,可否有人提供任何指针,因为我无法继续。
这是我的会话Factory…
@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);
}
System.out.println("enter fileMessageSource....."+ source.receive());
在fileMessageSource()
@Bean
中是坏的,只是因为你在那里做source.receive()
。这不是SOUT
的责任。
从另一个角度来看,如果你能和我们分享一些关于这件事的StackTrace,那就更好了…
还有一点:你在控制台看到System.out.println("message....."+message);
的结果了吗?