简体   繁体   English

删除集群中的已处理文件apache-camel

[英]Delete processed file apache-camel in a cluster

I use apache camel to process files received on a ftp channel. 我使用apache骆驼来处理在ftp通道上接收的文件。 My application is deployed in a cluster (4 nodes), for this I use RedisIdempotentRepository to ensure that a single node processes the file. 我的应用程序部署在一个集群(4个节点)中,为此,我使用RedisIdempotentRepository来确保单个节点处理该文件。 My problem is that I want to delete the file after processing, if I use delete=true , the node A that processed the file when it finishes and will delete the file, node B already deleted it because the node B will not go through the filter and therefore it will directly access the deletion. 我的问题是我想在处理后删除文件,如果我使用delete=true ,则在完成文件处理后处理该文件的节点A将删除该文件,节点B已经删除了该文件,因为节点B不会通过过滤器,因此它将直接访问删除内容。

I would like to know how to only allow node A to delete the file? 我想知道如何仅允许节点A删除文件?

from("sftp://host:port/folder?delete=true)
 .idempotentConsumer(simple("${file:onlyname}"),
     RedisIdempotentRepository.redisIdempotentRepository(redisTemplate, "camel-repo"))
 .bean("orderTrackingFileProcessor");

Configure the ftp endpoint to use the redis idempotent repository directly and not the idempotent consumer EIP in the route afterwards. 将ftp端点配置为直接使用redis幂等存储库,而不是随后使用路由中的幂等使用者EIP。 That ensures only 1 ftp consumer is processing the same file. 这样可以确保只有1个ftp使用者正在处理同一文件。

If you have Camel in Action 2nd ed book its covered in the 2nd half of the transaction chapter. 如果您有《骆驼在行动》第二版,则其内容将在交易章节的第二部分中介绍。

I workaround this using pollEnrich : 我使用pollEnrich解决此pollEnrich

adding delete step at end of processing: 在处理结束时添加删除步骤:

.pollEnrich(remoteLocation + "?delete=true&fileName=${file:name}");

Full Example Route: 完整示例路线:

String remoteLocation = "sftp://host:port/folder";

from(remoteLocation)
 .idempotentConsumer(simple("${file:onlyname}"),
     RedisIdempotentRepository.redisIdempotentRepository(redisTemplate, "camel-repo"))
 .bean("orderTrackingFileProcessor")
 .pollEnrich(remoteLocation + "?delete=true&fileName=${file:name}");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM