Apache NiFi With Rule Engine

in this quick post, we take a look at how to use Apache NiFi, and open source big data platform, to perform data manipulation.

Combining Apache NiFi with Rule engine is easy and fun. You can do some really great stuff with data manipulation, and I wrote some code for that purpose using Drools.Build or

Download Rule Engine

Download a compiled NiFi NAR here or Build from https://github.com/alefbt/NiFi-Rule-engine-processor

This is currently working only with JSON flow files.

(Licence: Apache2)
在这里插入图片描述
Then run the following:

git clone https://github.com/alefbt/NiFi-Rule-engine-processor cd NiFi-Rule-engine-processor mvn clean install package cp nifi-ruleengien-processor-nar/target/nifi-ruleengien-processor-1.0.nar /path-to-nifi/lib/

And (re)start NiFi.

Example

Create a NiFi Flow

  1. GetFile Processor
    Set property source folder : /some-project-path/IN
  2. RuleEngineProcessor
    Set the property DRL file path to /some-project-path/DRL/business_object_json_test1.drl
  3. PutFile Processor
    Set the property dest folder to /some-project-path/OUT

在这里插入图片描述

Create Files and Relevant Folders

在这里插入图片描述
Create a DRL file /some-project-path/DRL/business_object_json_test1.drl

package com.matrixbi.rules import com.matrixbi.objects.BusinessObject rule "Good Morning" when b: BusinessObject() eval( b.getAsInt("time") < 12 ) then b.set("greet","G00d Morning " + b.get("name")); end rule "Good Afternoon" when b: BusinessObject() eval(b.getAsInt("time") >=12 && b.getAsInt("time") < 16) then b.set("greet","Good Afternoon " + b.get("name")); end rule "Good Night" when b: BusinessObject() eval(b.getAsInt("time") >= 16) then b.set("greet","Good Afternoon " + b.get("name")); end

Create a JSON test file /some-project-path/IN/business_object_json_test1.json

{ "time": 11, "greet": "Default text", "name":"Yehuda" }

Activate all and run it.

Result
After a few moments, you should see business_object_json_test1.json in the/some-project-path/OUT folder file.
在这里插入图片描述
Source
在这里插入图片描述

Result
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值