应用程序部署在两个节点上时如何只读取一次文件 [英] How to read file only once when app deployed on two nodes
问题描述
我将逐行从 SFTP 位置读取文件:
I'm going to read files from SFTP location line by line:
@Override
public void configure() {
from(sftpLocationUrl)
.routeId("route-name")
.split(body().tokenize("\n"))
.streaming()
.bean(service, "build")
.to(String.format("activemq:%s", queueName));
}
但是这个应用程序将部署在两个节点上,我认为在这种情况下,我可以得到一个不稳定和不可预测的应用程序工作,因为文件的相同行可以被读取两次.在这种情况下,有没有办法避免这种重复?
But this application will be deployed on two nodes, and I think that in this case, I can get an unstable and unpredictable application work because the same lines of the file can be read twice. Is there a way to avoid such duplicates in this case?
推荐答案
Camel 有一些(实验性的)集群 功能 - 请参阅 此处.
Camel has some (experimental) clustering capabilities - see here.
在您的特定情况下,您可以建模一个路由,该路由在开始目录轮询时处于领导地位,从而防止其他节点选择(相同或其他)文件.
In your particular case, you could model a route which is taking the leadership when starting the directory polling, preventing thereby other nodes from picking the (same or other) files.
这篇关于应用程序部署在两个节点上时如何只读取一次文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!