Maintain separate rule files in drools

浪子不回头ぞ 提交于 2019-12-25 02:26:28

问题


I have a use-case where I need to maintain separate drl file for separate entities.
For example,
entity 1 has a set of facts which should be driven by drl1
entity 2 has a set of facts which should be driven by drl2

How should I implement this?

  1. Load the drl's and corresponding facts in separate Knowledge base and sessions
  2. Load all drl's and facts in single session.

I do not know how to achieve 2


回答1:


If you build your Knowledge Base along the lines given below, you can repeat adding another FileInputStream to the KieFileSystem.

KieServices kieServices = KieServices.Factory.get();
KieFileSystem kfs = kieServices.newKieFileSystem();
// repeat
FileInputStream fis = new FileInputStream( "simple/simple.drl" );
kfs.write( "src/main/resources/simple.drl",
                kieServices.getResources().newInputStreamResource( fis ) );
// end
KieBuilder kieBuilder = kieServices.newKieBuilder( kfs ).buildAll();

Results results = kieBuilder.getResults();
if( results.hasMessages( Message.Level.ERROR ) ){
    System.out.println( results.getMessages() );
    throw new IllegalStateException( "### errors ###" );
}
KieContainer kieContainer =
      kieServices.newKieContainer( kieServices.getRepository().getDefaultReleaseId() );
KieBase kieBase = kieContainer.getKieBase();
kieSession = kieContainer.newKieSession();


来源:https://stackoverflow.com/questions/24504728/maintain-separate-rule-files-in-drools

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!