Search code examples
javajbpm

jBPM: process deployment via API


I have create a business process flow using fluent API. I have few questions:

  1. With fluent API I am able to create a new process flow and validate it. But after build where that file (*.bpmn) is getting created?
RuleFlowProcessFactory factory = RuleFlowProcessFactory.createProcess("org.jbpm.HelloWorld");
factory
    .name("HelloWorldProcess")
    .version("1.0")
    .packageName("org.jbpm")
    .startNode(1).name("Start").done()
    .endNode(2).name("End").done()
    // Connections
    .connection(1, 2)
    .build();

Where HelloWorld.bpmn file will be created?

  1. Is there a way to create the process flow (*.bpmn file) inside kJar file with some API?
  2. Even if I somehow create a process using fluent API, how can I deploy it to a already existing kie server. I have a kie server running on localhost:8080, so is there a way to deploy the process created with fluent API on my kie-server.
  3. If not possible, is there a way to deploy the kJar to kie-server without using the business central. Is there any API for that?

Solution

  • For executing a process, you should create a Resource, which is used to create a KieBase. Using that KieBase, you can create a KieSession to execute the process.

    Using ProcessBuilderFactory.toBytes for that process definition will create a ByteArrayResource resource.

    // Build resource from Process
    KieResources resources = ServiceRegistry.getInstance().get(KieResources.class);
    Resource res = resources                         
                            .newByteArrayResource(factory.toBytes(process))
    

    Or, in your case, from the RuleFlowProcess process:

    Resource res = ResourceFactory
                   .newByteArrayResource(
                      XmlBPMNProcessDumper.INSTANCE.dump(process).getBytes());                          
    

    kieModule is automatically deployed to KieRepository if successfully built with buildAll().

    Take a look at the following example:

    // source path or target path must be set to be added into kbase                       
    res.setSourcePath("/tmp/processFactory.bpmn2"); 
    
    ​
    // Build kie base from this resource using KIE API
    ​KieServices ks = KieServices.Factory.get();
    ​KieRepository kr = ks.getRepository();
    ​KieFileSystem kfs = ks.newKieFileSystem();
    ​kfs.write(res);
    ​KieBuilder kb = ks.newKieBuilder(kfs);
    
    // kieModule is automatically deployed to KieRepository if successfully built.
    ​kb.buildAll(); 
    
    ​KieContainer kContainer = ks.newKieContainer(kr.getDefaultReleaseId());
    ​KieBase kbase = kContainer.getKieBase();
    ​
    // Create kie session using KieBase
    ​KieSessionConfiguration conf = ...;
    ​Environment env = ....;
    ​KieSession ksession = kbase.newKieSession(conf,env);
    
    ​// execute process using same process Id that is used to obtain ProcessBuilder instance
    ​ksession.startProcess("org.jbpm.HelloWorld")