I'm using Drools 6.2.0, and in my Maven project I have a few DRL files, each one with some different rules. The main idea, is to have a few workers in the project, each one with a KieSession that will receive the objects that will be evaluated by the rules in the files. I would like to bind a certain DRL file to a certain KieSession. I've seen that I can use the 'agenda-group' property, but I'm not sure how it works...
0
votes
1 Answers
0
votes
You can compile any DRL file to a KnowledgePackage and create a KnowledgeBase from it, which is the origin for a KnowledgeSession. You may even serialize the KnowledgePackage or KnowledgeBase for faster startup.
All of this can be done using the API, so there's no need for messing around with agenda groups.
EDIT This is code working with 6.2.0, using an unblemished API.
private KieSession kieSession;
public void build(String dir, String drl) throws Exception {
KieServices kieServices = KieServices.Factory.get();
KieFileSystem kfs = kieServices.newKieFileSystem();
FileInputStream fis =
new FileInputStream( dir + "/" + drl );
kfs.write( "src/main/resources/" + drl,
kieServices.getResources().newInputStreamResource( fis ) );
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();
}