0

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

Community
  • 1
  • 1
Chakradhar K
  • 501
  • 13
  • 40

1 Answers1

0

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.

Mawia
  • 4,220
  • 13
  • 40
  • 55
  • Thanks Mawia, But isn't that high availability expected business applications update their business logic flow through this? Or they just stop the server-> updated rules-> and go to start server? Please help me understand how drools is utilised to change business flow Thanks-Chakri – Chakradhar K May 13 '13 at 09:42
  • If you need dynamic drools then go for Drools Guvnor. It is complicated to setup the whole thing in Guvnor but if this is the exact requirement, it may be useful. – Mawia May 13 '13 at 09:45
  • 1
    **KnowledgeAgent** can continually update the rules as Guvnor changes them by releasing them. – Geoffrey De Smet May 14 '13 at 06:58