我目前正在尝试使用 SI DSL SFTP 功能推送一些文件。
我对这个 fwk 的使用不是很流利,所以我想知道是否有更好的方法来实现我想要实现的目标。
它的工作方式是这样的,除了复制文件时,其余调用处于超时状态...
奖励:是否有一些关于 SI DSL 的好读物(书籍或在线)? (cafe si sample 和引用除外..)
编辑:
- 此 SI 流程是否遵循 SI 良好实践?
- 尽管文件已正确复制到 sftp 服务器,但为什么我的休息调用以超时结束?
Java 配置:
@Configuration
@EnableIntegration
@IntegrationComponentScan
public class IntegrationConfig {
//flow gateway
@MessagingGateway
public interface FlowGateway {
@Gateway(requestChannel = "SftpFlow.input")
Collection<String> flow(Collection<File> name);
}
//sftp flow bean
@Bean
public IntegrationFlow SftpFlow() {
return f -> f
.split()
.handle(Sftp.outboundAdapter(this.sftpSessionFactory(), FileExistsMode.REPLACE)
.useTemporaryFileName(false)
.remoteDirectory(sftpFolder));
}
//sftp session config
@Bean
public DefaultSftpSessionFactory sftpSessionFactory() {
System.out.println("Create session");
DefaultSftpSessionFactory factory = new DefaultSftpSessionFactory(true);
factory.setHost(sftpHost);
factory.setPort(Integer.valueOf(sftpPort));
factory.setUser(sftpUser);
factory.setPassword(sftpPwd);
factory.setAllowUnknownKeys(true);
return factory;
}
}
一个 RestController 类:
@Autowired
private FlowGateway flowGateway;
@RequestMapping("/testSftp")
public String testSftp() {
flowGateway.flow(Arrays.asList(file1, file2, file3);
}
最佳答案
Spring Integration Java DSL 完全基于 Spring Integration 核心。因此,所有概念、方法、文档、示例等也适用于此处。
问题是什么?让我猜猜:“为什么它会超时并阻塞?”这对我来说很明显,因为我知道在哪里阅读,但对其他人来说可能不清楚。下次请更具体一些:SO 上有足够多的人可以将您的问题作为“不清楚”结束。
那么,让我们分析一下您拥有的东西以及为什么它不是您想要的。
Spring Integration 中的端点可以是单向
(Sftp.outboundAdapter()
) 或request-reply
(Sftp.出站网关()
)。当它是单向
时,没有什么可以返回并继续流程或发送回复,就像您的情况一样,这并不奇怪。
我确定您对回复不感兴趣,否则您使用了不同的端点。
在从 .split()
发送所有项目后,该过程恰好停止,并且正如您的代码所暗示的那样,没有任何内容可以发送回 @Gateway
:
Collection<String> flow(Collection<File> name);
具有非 void
返回类型需要 requestChannel
上下游流的回复
。
参见 Messaging Gateway获取更多信息。
也考虑使用
.channel(c -> c.executor(taskExecutor()))
在 .split()
之后将您的文件并行发送到 SFTP。
附言我不确定您还需要阅读什么,因为到目前为止,您的代码中的一切都很好,只有这个讨厌的reply
问题。
关于java - Spring Integration DSL SFTP 良好实践,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37869749/