spring-bootdroolskogito

Moving from Drools version 7 to Kogito


I have a domain specific application which has a drools version 7 libray as dependency so all the rules are loaded in application memory. I am looking to move to Kogito but having following doubts

  1. In drools i inject rules as drls in KnowledgeBuilder programmatically. My rules are very dynamic and keeps on changing so I update the kiesession using a scheduler. In the kogito-examples there is a KieRuntimeBuilder which automatically picks the drls from resource folder.
if ( ruleString != null ) {
  ruleSet = ResourceFactory.newReaderResource( new StringReader( ruleString ) );
 } else {
  ruleSet = ResourceFactory.newFileResource( ruleFilePath );
 }
 kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
 kbuilder.add( ruleSet, ResourceType.DRL );
 if ( kbuilder.hasErrors() ) {
  System.out.println( kbuilder.getErrors().toString() );
  throw new RuntimeException( BaseMessages.getString( PKG, "RulesData Error" ) );
 }

Ques: How to add drl in runtime in KieRuntimeBuilder ?

Ques : How to update the session periodically ?


Solution

  • How to add drl in runtime in KieRuntimeBuilder [in Kogito] ?

    You cannot, especially using Kogito, DRL are transformed at compile-time into executable model by the Quarkus extension or the maven plugin (when on Spring Boot). Then the application knowledge-base is considered immutable.

    How to update the session periodically [in Kogito] ?

    You cannot, same concepts as above.

    In a cloud-native settings, such as the one for which Kogito is recommended, your container/application should follow best practices such as Twelve-Factor App methodology, immutable images, etc.

    About the part where you said:

    My rules are very dynamic and keeps on changing so I update the kiesession using a scheduler

    You could consider automating this part, having a "template" Kogito application be built from the CI/CD side incorporating the changes from the knowledge assets, and if the tests are passing, you can do canary, blue/green, rollout deployment on your cloud-native platform, where your Kogito-based application is a rule/decision-based microservice.

    p.s.: consider Kogito a platform and framework such as Quarkus; you get many benefits if you follow the guidelines for Kogito. If your architecture is not cloud-native, or you don't want to use Kogito paradigms, you are not obliged to use Kogito.