Drools supports loading rules from files, one alternative that we are using in a similar use case is managing rules in a Git repo.
Component Start: Download the rules from git, and load them in a KieContainer.
Example:
KieServices kieServices = KieServices.Factory.get();
KieFileSystem kieFileSystem = kieServices.newKieFileSystem();
// Rule from string
gitRulesDao.getAllRulesFilesFromGitLab().forEach(r -> {
try {
addRuleToKie(kieFileSystem, kieServices, fileSystemBaseUrl, r);
} catch (IOException | GitLabApiException e) {
e.printStackTrace();
}
});
// build
KieBuilder kieBuilder = kieServices.newKieBuilder(kieFileSystem);
kieBuilder.buildAll();
// Test rule
Results results = kieBuilder.getResults();
if (results.hasMessages(Message.Level.ERROR)) {
...
}
//
KieModule kieModule = kieBuilder.getKieModule();
return new
KieContainerLocal(kieServices.newKieContainer(kieModule.getReleaseId()));
Rules Changes: When the rules are modified a git webhook sends a message to a Message Queue and the suscribed components reload the rules.
KieContainerLocal is an structure that stores a KieContainer in memory.