spring - Spring集成文件拆分器锁
问题描述
我有一个集成流程,它从名为“promo”的消息通道读取文件,然后拆分文件并对每个文件的特定行进行转换,然后由 ouboundAdapter 以追加模式逐行写入目录称为“生成”。然后,我有一个入站适配器,它使用固定延迟的轮询器从“生成”目录中读取,并将文件移动到目标位置以由不同的应用程序选择。如何确保从第二个流程中挑选的文件是完整的?我看到的情况是入站适配器移动到仍然由第一个流写入的目标文件。可以将锁添加到正在写入“生成”目录的文件中,以便第二个流程?
private IntegrationFlow promoChannelSubscriber(File generatedDir, GenericSelector storesFilter) {
return IntegrationFlows
.from("promo")
.filter(storesFilter)
.split(
Files.splitter()
.applySequence(true)
)
.transform(this::enrichXstoreFileHeader)
.handle(
Files.outboundAdapter(generatedDir)
.autoCreateDirectory(true)
.fileExistsMode(APPEND)
.appendNewLine(true)
)
.get();
}
private IntegrationFlow movePromotions(File generatedDir, Path destinationDirectory) {
return IntegrationFlows.from(
Files.inboundAdapter(generatedDir, comparingLong(File::lastModified))
.regexFilter(fileNamePattern),
cas -> cas.poller(
Pollers.fixedDelay(2, TimeUnit.SECONDS)
.maxMessagesPerPoll(promoConfig.getMaxMessagesPerPoll())
.errorChannel(errorChannelName)
))
.handle(
Files.outboundAdapter(destinationDirectory.toFile())
.deleteSourceFiles(true)
.temporaryFileSuffix(".tmp")
)
.get();
}
谢谢
解决方案
为什么使用 2 个流程?为什么在收到最后一个拆分时不执行第二个流程?
如果必须使用 2 个流,则需要写入与第二个流的过滤器不匹配的临时文件名。
然后,当文件完成后,将文件重命名为其最终名称。
您可以使用标记消息和路由器来检测文件结束情况。
有关示例,请参见file-split-ftp 示例应用程序。
推荐阅读
- php - 从数组中排除 NULL 和数值
- node.js - Amazon KMS - 预期用途
- docker - Docker 容器中的 dotnet ef 数据库更新失败并出现错误权限
- php - 函数中的 PHP curl 不返回 antyhing
- image - Webpack 不使用绝对路径加载本地图像
- node.js - 使用 Nginx 作为 AWS EC2 上的代理服务器,使用 socket.io 运行 NodeJs 应用程序
- ios - IOS 11.4.1 上的 AVFoundation、AVAudioSessionRouteChange 行为不正确
- php - Laravel:如何在子进程中通过 Eloquent 更新 MySQL?
- windows - 通过 Electron 访问当前高亮文本
- php - 1 个模型中的 2 个查询 (CodeIgniter)