【发布时间】:2015-07-14 15:13:44
【问题描述】:
我在 spring DSL 中创建了一个 Sftp 出站流,我还在 Sftp 出站流之上创建了一个文件入站流,用于从我的本地目录中查找文件并将其发送到负责复制的消息通道文件到远程目录,但是当我运行我的代码时,没有文件被复制到远程目录中。所以我陷入了这一点,任何人都可以提供任何指向它的指针,因为我无法继续。
这是我的会话工厂...
@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);
}
【问题讨论】: