0
votes

I am new to drools. I just want to understand how to dynamically update rules at run time. Considering Drools - Ability to define rules at runtime?

I wrote a code:

 while(true){
    session = fetchStatefulSession();//Some method to get drools session
    system.out.println("enter text");
    //Some code to read input
    session.fireAllrules();
 }

Now by the time I give input I have updated .drl rules file. Even after that the result is same on,

 session.fireAllrules();

as it was earlier. That is the changes in rules are not reflected.

I am not sure is this proper way to use, dynamic loading of rules. Please suggest me

Thanks Chakri

1

1 Answers

0
votes

Your code is only getting the session which is still using the same .drl file. Your code needs to include loading the .drl files as well.

knowledgeBuilder.add(ResourceFactory.newClassPathResource(rulesFile, YourClass.class), ResourceType.DRL);

But still I doubt it will work or not because loading files at run time is very prone to error and difficult to maintain.