Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

javaarchjdr/DroolsRuleEngine

Open more actions menu
 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Drools Rule Engine

A Simple Rule Engine Built over Drools. Normal REST POST calls are made to update and create the rules. Rules can be executed via REST POST Calls as well.

Rules are kept into different shards. 10 knowledge shards are used to have faster performance while saving new Rules. Rules are also saved to DB so when we redeploy/re-run the project rules can be reloaded into Drools knowledgebase.

Apache Velocity Template Engine is used to convert the JSON rules into Drools Rules.

Installation

Being a spring boot project, All we need is to resolve all the dependencies. Also setup a MySQL DB to persist the rules. Look into application.properties for DB setup

Usage

Add A Rule :

POST : "localhost:8080/offer"
{
	"id" : 1,
	"ruleName" : "SBI",
	"discountAmount" : "10",
	"price" : 10000
}

Add An Item :

POST : "localhost:8080/addItem"
{
	"name" : "Mobile",
	"cardType" : "SBI",
	"price" : 11000
}

Execute Rules :

POST : "localhost:8080/order"
{
    "name": "Mobile",
    "cardType": "SBI",
    "discount": 0,
    "price": 11000,
    "id": 2
}

Load Test The Rule Engine

I have created a k6.js Script for creating thousands of rules. Script is as Follows

import http from "k6/http";
import { sleep } from "k6";

export default function() {
  for(var i = 1001; i < 10000; i++) {
    var url = "http://localhost:8080/offer";
    var payload = JSON.stringify({
      id : i,
	    ruleName : Math.random() >= 0.5 ? "SBI" : "HDFC",
	    discountAmount : "10",
	    price : 1000+(i*100)
    });
    var params =  { headers: { "Content-Type": "application/json" } }
    http.post(url, payload, params);
    sleep(1);
  }
};

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

Future Plans

  1. Get A better Sharding Strategy for better performance.
  2. Running Different shards in different threads.

About

A drools rule engine, with dynamic rules updated through rest APIs

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Java 100.0%
Morty Proxy This is a proxified and sanitized view of the page, visit original site.