0
votes

We are using jBPM for our process flow needs. However, this jBPM process is triggered via REST APIs from our Java code. Thus,

  • Java App had application code and we trigger the jBPM process from here using APIs.

  • jBPM instance( JBPM 6.1 ) is being used for the process flow execution. This instance is also there but is accessed remotely.

Now, we are trying to integrate the Drools engine for our business rules needs. What we want is that we will store all our rules in the database and these rules will be loaded when the JBPM server starts up( or when the Java VM boots up). Thus, the rules will be loaded into the working memory and be available for use in the JBPM process when needed.

2 questions here:-

1) How do we get this done ( loading rules from the database and getting them into the working memory of JBPM and Drools right when the JBPM server loads up)?

The idea is that once the rules are loaded, they can be accessed anywhere in process as needed.

Also, if we wanted to update the jBPM variable with the value obtained from the Drools rules what were loaded earlier, how can we do that ?

1

1 Answers

0
votes

At startup, you can do this by loading the resources from the database and converting the strings to byte arrays and creating the knowledge base:

    Resource workflowResource = ResourceFactory.newByteArrayResource(workflowBpmnByteArray);
    Resource rulesResource = ResourceFactory.newByteArrayResource(resourceByteArray);

    KnowledgeBuilder knowledgeBuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    knowledgeBuilder.add(workflowResource, ResourceType.BPMN2);
    knowledgeBuilder.add(rulesResource, ResourceType.DRL);

    KnowledgeBaseConfiguration config = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
    KnowledgeBase knowledgeBase = KnowledgeBaseFactory.newKnowledgeBase("knowledgeBase", config);
    knowledgeBase.addKnowledgePackages(knowledgeBuilder.getKnowledgePackages());

Remember that adding resources to the knowledge builder will cause them to be compiled so you should check for errors before creating the knowledge base.

The resulting knowledge base can be cached in memory and used for creating process instances within your application.