Apache nifi Nifi从数据库添加属性
我目前正在从Nifi中的FTP获取文件,但在获取文件之前,我必须检查一些条件。情况是这样的 列出FTP->检查条件->获取FTP 在检查条件部分,我从数据库中获取了一些值,并与文件名进行了比较。所以,我可以使用update属性从数据库中获取一些记录,并使其成为这样吗Apache nifi Nifi从数据库添加属性,apache-nifi,Apache Nifi,我目前正在从Nifi中的FTP获取文件,但在获取文件之前,我必须检查一些条件。情况是这样的 列出FTP->检查条件->获取FTP 在检查条件部分,我从数据库中获取了一些值,并与文件名进行了比较。所以,我可以使用update属性从数据库中获取一些记录,并使其成为这样吗 列出FTP->Update Attribute(从DB)->Route on Attribute->Fetch FTP我认为您的流如下所示 流量: ${filename:substringAfter('_'):toDate("yyy
列出FTP->Update Attribute(从DB)->Route on Attribute->Fetch FTP我认为您的流如下所示 流量:
${filename:substringAfter('_'):toDate("yyyy-MM-ddHH:mm:ss"):toNumber()
:gt(${db_time:toDate("yyyy-MM-ddHH:mm:ss"):toNumber()})}
RouteOnAttribute配置:
${filename:substringAfter('_'):toDate("yyyy-MM-ddHH:mm:ss"):toNumber()
:gt(${db_time:toDate("yyyy-MM-ddHH:mm:ss"):toNumber()})}
我假设文件名类似于fn_2017-08-2012:09:10,executesql已返回2017-08-2012:08:10
表达式:
${filename:substringAfter('_'):toDate("yyyy-MM-ddHH:mm:ss"):toNumber()
:gt(${db_time:toDate("yyyy-MM-ddHH:mm:ss"):toNumber()})}
通过使用上述表达式,我们获得了与ListFTP相同的文件名值,并且通过使用EvaluateJsonPath
处理器添加了db_time
属性,我们将时间戳更改为数字,然后进行比较
有关NiFi表达式语言的更多详细信息,请参阅链接
因此,如果我正确理解您的用例,就好像您使用外部数据库只是为了跟踪目的。所以我想只有最新处理的时间戳就足够了。在这种情况下,我建议您使用NiFi提供的DistributedCache
处理器和控制器服务,而不是依赖外部数据库
使用此方法,您的流程如下所示:
ListFile-->FetchDistributedMapCache--(成功)-->RouteOnAttribute->FetchFile
配置FetchDistributedMapCache
1.ListFTP //to list the files
2.ExecuteSQL //to execute query in db(sample query:select max(timestamp) db_time from table)
3.ConvertAvroToJson //convert the result of executesql to json format
4.EvaluateJsonPath //keep destination as FlowfileAttribute and add new property as db_time as $.db_time
5.ROuteOnAttribute //perform check filename timestamp vs extracted timestamp by using nifi expresson language
6.FetchFile //if condition is true then fetch the file
- 缓存条目标识符-这是缓存的密钥。将其设置为类似于
lastProcessedTime
- 将缓存值放在属性中-无论您在此处给出什么名称,都将添加为FlowFile属性,其值为缓存值。提供名称,如
latestTimestamp
或lastProcessedTime
配置RouteOnAttribute
1.ListFTP //to list the files
2.ExecuteSQL //to execute query in db(sample query:select max(timestamp) db_time from table)
3.ConvertAvroToJson //convert the result of executesql to json format
4.EvaluateJsonPath //keep destination as FlowfileAttribute and add new property as db_time as $.db_time
5.ROuteOnAttribute //perform check filename timestamp vs extracted timestamp by using nifi expresson language
6.FetchFile //if condition is true then fetch the file
单击属性
选项卡中的(+)按钮,创建新的动态关系。给它起个名字,比如success
或matches
。让我们假设,您的文件名的格式为somefile\u 1534824139
,即它有一个名称和一个\u
以及附加的历元时间戳
在这种情况下,您可以利用NiFi表达式语言
,并利用它提供的功能。因此,对于新的动态关系,可以使用如下表达式:
- 成功-
${filename:substringAfter('''u'):gt(${lastProcessedTimestamp})}
FetchDistributedMapCache
中,您已使用值lastProcessedTimestamp
配置属性Put Cache Value in Attribute
有用的链接