简体   繁体   中英

How to feed data from an external Java Application into a Drools BRMS and get data back?

Basically I first created a Drools project in Eclipse and designed a basic rules application, that puts an object into the working memory and fires all the rules (using ksession), which worked correctly. I want to find out, how to call this rules application from a different Java application (different eclipse project), feed it the input object variables and get the calculated variables (from firing rules) back to the new Java application, effectively isolating rules processing from the user interface. Found no good examples as to how this could be achieved yet. I am a newbie when it comes to business rules managment systems.

You can create a utility that creates a static kSession. Then create a method that takes your input and fires your rules something like the following(untested code). Whenever you wanted to use it you could call.

DroolsTest.getInstance().fire(input);

public class DroolsTest {

  private static KieSession kSession;  
  private DroolsTest instance;

  private DroolsTest(){
    if(null == instance){
      // load up the knowledge base
      KieServices ks = KieServices.Factory.get();
      KieContainer kContainer = ks.getKieClasspathContainer();
      kSession = kContainer.newKieSession("ksession-rules");
    }
  }

  public static DroolsTest getInstance(){
    if(null = instance){
      instance = new DroolsTest();
    }
  }

  public static void fire(Object input) {
    kSession.insert(input);
    kSession.fireAllRules();
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM