A Simple Rules Engine
For one of my project, I needed a simple rules engine.
I like the DecisionDag that Mandar Jog built. It uses Commons JEXL and allows rules to be defined in plain english.
In my use case, I had following goals.
- keep it simple (KISS)
- rules engine as micro-service (deployable to cloud).
- a rules catalog of sorts that allowed new versions of the rules to be added and older ones removed.
- ability to calculate within the rule and return results.
This is a simple rules engine built with spring-boot in java.
The rules are in plain javascript.
Nashorn sccript engine allows runtime loading and evaluation of rules.
Instructions
-
Install the app by cloning the repository rulesengine
-
Build and run the app
$ cd rulesengine $ gradlew bootRun
-
Call rest end-points.
$ curl -v 'http://localhost:8080/api/rules/WhatToDo?family_visiting=yes' $ curl 'http://localhost:8080/api/rules/WhatToDo?family_visiting=no&money=poor&weather=good' $ curl 'http://localhost:8080/api/rules/WhatToDo?family_visiting=no&money=poor&weather=cold' $ curl 'http://localhost:8080/api/rules/WhatToDo?family_visiting=no&money=rich&weather=cold'
Cloud
Meet PCF Dev. It is a simplifed, and minimized version of the Pivotal Cloud Foundry intended for your local machine. And Getting started is simple.
#####Deploy to cloud
-
Target the cloud instance
$ cf login -a api.local.pcfdev.io --skip-ssl-validation API endpoint: api.local.pcfdev.io Email> admin Password> admin
-
Build and deploy to cloud
$ cd rulesengine $ ./gradlew assemble $ cf push -f manifest.xml
-
Test the cloud service
$ curl -v 'http://simplerules.local.pcfdev.io/api/rules/WhatToDo?family_visiting=yes' $ curl 'http://simplerules.local.pcfdev.io/api/rules/WhatToDo?family_visiting=no&money=poor&weather=good' $ curl 'http://simplerules.local.pcfdev.io/api/rules/WhatToDo?family_visiting=no&money=poor&weather=cold' $ curl 'http://simplerules.local.pcfdev.io/api/rules/WhatToDo?family_visiting=no&money=rich&weather=cold'