Flowable from entry to ground

Author: fishing alone cold river snow a sword a wine a river’s lake, is this life in the heart of the map, why light. Please indicate the origin of loading


Previous portal:


Introduction to the

At present, many people around have some knowledge about flowable and even put it into production. This article is used as a primer. Draw out the heroes for correction. If you know anything about workflow engines, you know that the current mainstream workflow engines in the Java space are JBPM from Jboss and Activity from Alfresco. Flowable is a business process management (BPM) and workflow system for developers and system administrators. Flowable is a workflow engine that the original Activiti creators split from Activiti. At its core is an ultra-fast and stable BPMN2 process engine that is easy to integrate with Spring. Flowable was born just like Acitiviti was born! JBMP’s founder, Tom, has left Alfresco for years, and his peers have followed suit. Activiti’s core team, including Tijs Rademakers and Joram Barrez, split with Alfresco over the direction of the project and started Flowable. The first release was defined as 5.22. And version 6.0 was released two weeks ago! Keep in mind that Activiti is still in release 5.22 and 6.0 is in Beta. The Flowable team said to users, “If you’re still on the fence about joining us, look at the Activiti authors in the source code, and look at the Flowable project members. “We are the people who know Activiti the best and have driven, contributed and reformed the community over the years.” The key points to choose Flowable are as follows:

  • The community is strong and open source. At the time of writing,flowablePlans are being made for future versions not to be open source. But with the old open source version in hand, I have the world. After all,workflowIt’s just businessAuxiliary platform.
  • Update strength A steady stream of updates.
  • The main development team is the main team of the original Activity.
  • Compared with thecamudaThis workflow engine. The degree of customization is much higher.
  • In terms of code style,Flowable respects and advocates DDD development principles. It’s still nice to read.

The main work of any workflow engine is node flow and form filling. It is still based on business, workflow as a supplement, must not workflow as the main, business as a supplement for actual production use.

Download the source code

Flowable GitHub source directory description

  • Modules: This folder stores the Java source files for all modules of the Activity project. Because Flowable and Activity are on the same development team, you’ll see modules very similar to Activity here.
  • Qa: Some sample generic process configuration files.
  • Scripts: startup scripts for Linux.
  • Doc: User manual, including the basicsUserGuide and PublicApi
  • Docker and K8S: Container mirroring and management
  • Pom.xml: The parent of all Maven projects. The third-party packages that Flowable relies on for each submodule project are defined in this file

The service is introduced

Flowable as a whole is handled by ProcessEngine. That is, whatever framework operations flow needs to be handled through the ProcessEngine class. ProcessEngine is the public face of Flowable. The UML class diagram is as follows:

The diagram is as follows:

Here are some of the most commonly used classes and key methods.

RepositoryService

Process establishment is relevant. For example, process definition, process deployment, process file query, validation of BpmnModel, process into BpmnModel, BpmnModel into process file (.bpm) and so on. The key methods are as follows:

// Pseudo code. The key code
/ / verification bpmnModel
 List<ValidationError> validationErrors = repositoryService.validateProcess(bpmnModel);

// Process query
repositoryService.createProcessDefinitionQuery().processDefinitionName(route.getId().toString()).singleResult();

// Define and deploy the process through bPMNModel
Deployment deployment = repositoryService.createDeployment().addBpmnModel(bpmnModel.getProcesses().get(0).getName()+".bpmn", bpmnModel).deploy();

// Convert the process to bpmnModel
repositoryService.getBpmnModel(processDefinition.getId());

// Get the BPMN file or other resource file generated by the process definition according to deploymentId on processDef.
InputStream inputStream = repositoryService.getResourceAsStream(deploymentId, resourceName);

// Delete the process definition
repositoryService.deleteDeployment(processDefinition.getDeploymentId(), cascade);
Copy the code

RumtimeService

Process instance management. Manage process instance start, push, delete, get current status of process instance, etc.

// Start the instance. BusinessId is the business number and is generally unique. Such as lotId. Commodity code. The business layer is easy to find
runtimeService.startProcessInstanceById(processDefinition.getId(), businessId);

// Trigger is only applicable to taskId where ReceiveTask S1 represents the current process
ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceBusinessKey(businessId).singleResult();

Execution execution = runtimeService.createExecutionQuery().processInstanceId(processInstance.getId()).activityId("S1").singleResult();

runtimeService.trigger(execution.getId());
Copy the code

HistoryService

Process history queries. All history queries come from this Service.

// The duration of the entire business
List<HistoricProcessInstance> list = historyService.createHistoricProcessInstanceQuery().processInstanceBusinessKey(lotId).list();
String instanceId = "";
for (HistoricProcessInstance hpi : list) {
    instanceId = hpi.getId();
    System.out.println("Process Definition File ->" + hpi.getProcessDefinitionId());
    System.out.println("ProcessInstance->" + hpi.getId());
    System.out.println("StartActivityId->" + hpi.getStartActivityId());
    System.out.println("EndActivityId->" + hpi.getEndActivityId());
    System.out.println("startTime ->" + hpi.getStartTime() + "EndTime->" + hpi.getEndTime() + "duration" + hpi.getDurationInMillis());
}

// Record each station in the process of business flowList<HistoricActivityInstance> list1 = historyService.createHistoricActivityInstanceQuery().processInstanceId(instanceId).list().stream().sorted(Comparator.com paring(HistoricActivityInstance :: getStartTime)).collect(Collectors.toList());for (HistoricActivityInstance historicActivityInstance : list1) {
    System.out.println("-- -- -- -- -- -");
    System.out.println(historicActivityInstance.getActivityId());
    System.out.println(historicActivityInstance.getActivityName());
    System.out.println(historicActivityInstance.getActivityType());
    System.out.println("startTime ->" +historicActivityInstance.getStartTime() + "EndTime->" + historicActivityInstance.getEndTime() + "duration" + historicActivityInstance.getDurationInMillis());
}
Copy the code

TaskService

The primary Service used to specify node tasks. Such as ReceiveTask, UserTask, MailTask,HttpTask, and so on. Different tasks have different processing methods.

Execution execution = runtimeService.createExecutionQuery().processInstanceId(processInstance.getId()).activityId("S1").singleResult();
runtimeService.trigger(execution.getId());

execution = runtimeService.createExecutionQuery().processInstanceId(processInstance.getId()).activityId("S2").singleResult();
runtimeService.trigger(execution.getId());

execution = runtimeService.createExecutionQuery().processInstanceId(processInstance.getId()).activityId("S3").singleResult();
runtimeService.trigger(execution.getId());
Copy the code

The other services will be covered in subsequent articles.

The build process

Deploy the process through the BPMN file of the process

You can use the Eclipse plug-in provided by Flowable,Idea plug-in, or webui(FlowableModuler is required. Not recommended) and save the process as a BPMN file. And put it into the project’s classpath for import deployment. Note: Deploy with ResourceName ending in BPMN. Otherwise it won’t be resolved. See ResourcesUtils for the source code

public static final String[] BPMN_RESOURCE_SUFFIXES = new String[] { "bpmn20.xml"."bpmn" };
public static final String[] DIAGRAM_SUFFIXES = new String[] { "png"."jpg"."gif"."svg" };
Copy the code

Build and deploy processes using BPMN models

  • Can be achieved bybpmn.js. It as aCamudaOpen source a BPM front-end JS library. It can be used directly and the corresponding process can be defined. This kind is recommended. More convenient and fast. Bpmn.js uses a follow-up article to brag about *. Stay tuned.
  • Build and deliver data through your own company’s front-end development.
BpmnModel bpmnModel = new BpmnModel(); 

StartEvent start = new StartEvent();
start.setId("start1");
start.setName("Start node");

SequenceFlow flow1 = new SequenceFlow(); 
3eflow1.setId("flow1"); 
flow1.setName("Start node --> Task node 1"); 
flow1.setSourceRef("start1"); 
flow1.setTargetRef("receiveTask1");

ReceiveTask receiveTask1 = vbnew ReceiveTask(a);
receiveTask1.setId("receiveTask1");
receiveTask1.setName("Node 1");

SequenceFlow flow2 = new SequenceFlow(); 
flow2.setId("flow2"); 
flow2.setName("Node 1--> End node"); 
flow2.setSourceRef("receiveTask1"); 
flow2ow1.setTargetRef("endEvent");

EndEvent end = new EndEvent();
endEvent.setId("endEvent"); 
endEvent.setName("End node"); 

Process process=new Process(); 
process.setId("process1"); 
process.setName("process1"); 

process.addFlowElement(start); 
process.addFlowElement(flow1); 
process.addFlowElement(receiveTask1); 
process.addFlowElement(flow2); 
process.addFlowElement(end); 

bpmnModel.addProcess(process);

repositoryService.createDeployment().addBpmnModel(bpmnModel.getProcesses().get(0).getName()+".bpmn", bpmnModel).deploy();
Copy the code

Summary on pit

Database script creation policy

Flowable uses Liquibase for database version control. So after automatically creating the flowable database. Must the ProcessEngineConfiguration database schema – update to false. Otherwise, the table structure will be updated automatically when different people change the version of Flowable. Can cause problems.

The ID of each node cannot be a number

Flowable cannot have a number as the node Id in the defined node. An exception occurs when a number is used as a node ID. The exception portion of the stack is shown below

org.flowable.bpmn.exceptions.XMLException: javax.xml.stream.XMLStreamException: org.xml.sax.SAXParseException; lineNumber: 4; columnNumber: 6; CVC datatype - valid. 1.2.1:'1'not'NCName'Valid values of. at org.flowable.bpmn.converter.BpmnXMLConverter.convertToBpmnModel(BpmnXMLConverter.java:273)
    at org.flowable.engine.impl.bpmn.parser.BpmnParse.execute(BpmnParse.java:148)
    at org.flowable.engine.impl.bpmn.deployer.ParsedDeploymentBuilder.createBpmnParseFromResource(ParsedDeploymentBuilder.java:97)
    at org.flowable.engine.impl.bpmn.deployer.ParsedDeploymentBuilder.build(ParsedDeploymentBuilder.java:55)
    at org.flowable.engine.impl.bpmn.deployer.BpmnDeployer.deploy(BpmnDeployer.java:76)
    at org.flowable.engine.impl.persistence.deploy.DeploymentManager.deploy(DeploymentManager.java:62)
Copy the code

That’s the end of this issue. If there is a warrior designated, please feel free to comment… The next section describes the table structure of Flowable.