简体   繁体   English

如何将数据从外部Java应用程序馈送到Drools BRMS并取回数据?

[英]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. 基本上,我首先在Eclipse中创建了一个Drools项目,并设计了一个基本的规则应用程序,该应用程序将一个对象放到工作内存中并激发所有正常工作的规则(使用ksession)。 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. 我想找出如何从另一个Java应用程序(不同的eclipse项目)中调用此规则应用程序,将输入对象变量提供给它,并将计算出的变量(从触发规则中)返回给新的Java应用程序,从而有效地隔离规则处理从用户界面。 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. 您可以创建一个创建静态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); DroolsTest.getInstance()火(输入)。

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();
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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