【发布时间】:2017-01-03 21:52:44
【问题描述】:
如何仅在成功的 FTP 文件传输时触发消息发送到 JdbcOutboundGateway?
我有以下集成流。它可以根据需要将文件上传到 FTP 服务器。但是,然后我需要写入文件已成功上传的数据库,或者如果 FTP 上传失败,则更新记录。我无法弄清楚如何在文件传输成功时启动数据库更新。在我尝试继续流程的任何地方,它都会抛出一个异常,说明它是“单向”的。
- ftpProps 包含各种 FTP 设置的所有配置值
- outboundMessages 是放置需要通过 FTP 发送的消息的通道
- ftpSessionFactoryFactory 从配置文件中的值构建所有各种 FtpSessionFactory 对象,然后路由器将通过检查标头值来确定将消息发送到哪个对象
流程:
@Bean
public IntegrationFlow fromOutboundChannelToFtp(OutboundConfigurationProperties ftpProps,
@Qualifier(OUTBOUND_CHANNEL) MessageChannel outboundMessages,
@Qualifier(FTP_SESSION_FACTORY_FACTORY) FtpSessionFactoryFactory ftpSessionFactoryFactory) {
return IntegrationFlows.from(outboundMessages)
.route(RECEIVER_HEADER_SPEL, mapping -> {
for (String receiverId : ftpProps.getFtp().keySet()) {
mapping.subFlowMapping(receiverId, sf -> {
sf.handleWithAdapter(adapter ->
adapter.ftp(ftpSessionFactoryFactory.getFactory(receiverId))
.fileNameExpression(FILENAME_HEADER_SPEL)
.autoCreateDirectory(true)
.remoteDirectory(ftpProps.getValue(receiverId, FtpProp.DIRECTORY))
);
});
}
})
.get();
}
【问题讨论】:
标签: java spring spring-boot spring-integration