Search code examples
javaspringdrools

Drools fire only those rules which names are configured in a file Spring boot


I had a Yml(I am okay with any extension ) file where I am storing all the rules' names. I need to fire all the names that are configured in this file. When I want to Disable a rule for execution I will just comment or I will remove that rule name in that file so that the rule will not be executed.


Solution

  • Introduce EligibleRules with Set<String> rules and make additional condition for each rule.

    rule "Rule 1"
    when
        EligibleRules(rules contains "Rule 1")
        ...
    

    insert single copy of EligibleRules into the session, update set of rules before fireAllRules() when the list of eligible rules changes and update fact handle for drools to notice the change.