restdroolsrule-enginekie-workbench

Drools: Executing multiple rules simultaneously via REST


I am new to drools. I want to fire multiple rules simultaneously depending on the condition. I am using batch-execution command as follows, but it gives me error : "Bad request, no commands to be executed - either wrong format or no data"

{
"batch-execution":{
    "lookup":"defaultKieSession",
    "commands":[
        {
            "insert":{
                "out-identifier":"TestAdvance",
                "object":{
                    "LoanAdvance":{
                        "tenure":4,
                        "isBlacklisted":false
                    }
                }
            }
        },
        {
            "insert":{
                "out-identifier":"TestAdvance",
                "object":{
                    "LoanAdvance":{
                        "tenure":3,
                        "isBlacklisted":false
                    }
                }
            }
        },
        {
            "fire-all-rules":{

            }
        }
    ]
}
}

My rule in guided decision table looks like this: the rule

I want to make a REST request to the rule engine and get the result set as a list. Please confirm if my JSON request is correct. Or is there any better way to achieve the same? Any help would be appreciated.

Thanks & Regards


Solution

  • you are using incorrect json request format. With JSON request payload no need to use ''batch-execution", remove that. And correct JSON request will look like as:

    {
      "commands":[
             {
            "insert":{
               "out-identifier":"obj",
               "object":{
                  "example.project4_91839699.Person":{
                     "firstName":"abc",
                     "lastName":"abc", 
                     "hourlyRate":22,
                     "wage":100    
                  }
               }
            }
         },{
            "insert":{
               "out-identifier":"obj2",
               "object":{
                  "example.project4_91839699.Person":{
                     "firstName":"xyz",
                     "lastName":"xyz", 
                     "hourlyRate":24,
                     "wage":100    
                  }
               }
            }
         }
         {
            "fire-all-rules":""
         }
      ]
    

    }