Reputation: 643
I am using spring boot drools. I would like to maintain say 3 different drl files for different context as the rules are different for different context. In this case should I create 3 key KieContainer for each context or is it possible to handle in just on kie container? Note: for each context I have to invoke only the corresponding drl rules
@Bean
public KieContainer getKieContainer() {
KieFileSystem kieFileSystem = kieServices.newKieFileSystem();
kieFileSystem.write(ResourceFactory.newFileResource("ctxt1.drl")));
kieFileSystem.write(ResourceFactory.newFileResource("ctxt2.drl")));
KieBuilder kb = kieServices.newKieBuilder(kieFileSystem);
kb.buildAll();
KieModule kieModule = kb.getKieModule();
KieContainer kieContainer = kieServices.newKieContainer(kieModule.getReleaseId());
return kieContainer;
}
this is how I invoke rule. Here I would like to invoke context based drl file rules in the session. How to use KieBase based KieSession?
KieSession kieSession = kieContainer.newKieSession();
kieSession.insert(RequestPOJO);
kieSession.fireAllRules();
kieSession.dispose();
Upvotes: 0
Views: 945
Reputation: 2398
Based on the limited description, sounds like "different context" can be identified with a Knowledge Base (KieBase
).
You can create 1 KJAR with the 3 different DRL files, making sure (e.g.: via package) they correspond to 3 different KieBases.
Something ~like:
<kmodule>
<kbase name="KBase1" packages="org.acme,org.context1" />
<kbase name="KBase2" packages="org.acme,org.context2" />
<kbase name="KBase3" packages="org.acme,org.context3" />
...
</kmodule>
Then you could create 1 KieContainer, which contains the single KJAR containing the "multiple contexts" (KieBases).
At that point, from the KieContainer, you can create a KieSession with the specific KieBase you want.
Upvotes: 1