Detailed explanation and application of Activiti workflow engine

picture

1. Introduction

Activiti is an open source workflow engine that defines processes based on the BPMN2.0 standard. It can extract complex business processes from the business system and define them using the special modeling language BPMN2.0. The business processes are executed according to the pre-defined processes, realizing that the system processes are managed by Activiti, reducing the business system due to process Change the workload of system upgrade and transformation, thereby improving the robustness of the system and reducing system development and maintenance costs.

Activiti provides a rich API and tools to support developers using the BPMN2.0 modeling language to define and manage workflows. It also provides a visual editor to help you create and edit workflows.

2. Characteristics

  • Free and open source, low cost of use.

  • Process Engine: Activiti provides a Java-based process engine that can execute BPMN 2.0 process definitions. The engine supports advanced features such as parallel and sequential execution, conditional branching, service tasks, gateways, events, mediation flows, and more.

  • Form Designer: Activiti provides an easy-to-use form designer for creating and editing process definitions. The designer supports drag-and-drop and data binding, making it easy to create complex forms.

  • Graphical Modeler: Activiti provides an Eclipse-based graphical modeler for creating BPMN 2.0 process models. The modeler supports multiple layout options, drag-and-drop elements, automatic filling and other functions, making the creation of process models easier and more intuitive.

  • RESTful API: Activiti provides a set of RESTful API for communicating with the process engine. The API supports a variety of operations, such as deploying process definitions, starting process instances, querying task lists, etc. In addition, the API also supports asynchronous calls, which can perform operations without blocking the main thread.

  • Multi-language support: Activiti supports multiple programming languages, including Java, JavaScript, Groovy, Python, etc. This allows developers to write process definitions and service tasks using a language they are familiar with.

  • Scalability: Activiti has good scalability and its functions can be extended through the plug-in mechanism. For example, you can use workflow service plug-ins to integrate external systems, or use decision service plug-ins to implement functions such as conditional branching.

3. Database support

The databases supported by the Activiti workflow engine include: h2, mysql, oracle, postgres, mssql, db2, etc.

4. Activiti table description

4.1 Process deployment related table:

  • act_re_deployement deployment object table 

  • act_rep_procdef process definition table 

  • act_ge_bytearray resource file table 

  • act_ge_prperty primary key generation policy table (for the primary key ID of the deployment object table)

4.2 Process instance related table:

  • act_ru_execution The execution object table being executed (including execution object ID and process instance ID, if there are multiple threads, the process instance ID may be different)

  • act_hi_procinst process instance history table  

  • act_hi_actinst stores all completed tasks in history

4.3 Task task related table:

  • act_ru_task agent task list (only corresponding nodes are UserTask)

  • act_hi_taskinst Agent task history table (only corresponding to nodes that are UserTask) 

  • act_hi_actinst All node activity history table (the activity history of all nodes corresponding to the process, the activities of all nodes from the start node to the end node will be recorded)

4.4 Process variable table:

  • act_ru_variable process variable table being executed 

  • act_hi_variable process variable history table

5. Core API

5.1 ProcessEngine

Description: The core class in Activiti, other classes are derived from it.

5.2 RepositoryService

Description: Activiti’s warehouse service class. The so-called warehouse refers to the two files of the process definition document: bpmn file and process picture. This service can be used to delete the deployed process definition.

5.3 RuntimeService

Description: Activiti's process execution service class can obtain a lot of information related to process execution from this service class.

5.4 TaskService 

Description: It is the task service class of Activiti. You can get task-related information from this class, such as the personal to-do and user group to-do tasks currently being executed.

5.5 HistoryService

Description: Activiti's class for querying historical information. After a process is executed, this object provides us with query historical information, which can track the running status of all to-do nodes corresponding to the process instance.

5.6 ProcessDefinition 

Description: Process definition class, resource files, etc. can be obtained from here.

5.7 ProcessInstance 

Description: Represents the execution instance of the process definition. When a deployed flow chart is started, the process has only one process instance data, but it can have multiple process tasks, and each task corresponds to the corresponding process node in the flow chart.

6. Spring Boot integrates Activiti

The steps for Spring Boot to integrate the Activiti workflow engine are as follows:

6.1 Add dependencies

Add the following dependencies in the pom.xml file:

<dependency>
    <groupId>org.activiti</groupId>
    <artifactId>activiti-spring-boot-starter-basic</artifactId>
    <version>7.1.0.M6</version>
</dependency>

6.2 Configure Activiti

Add the following configuration in the application.properties file:

spring.activiti.database-schema-update=true
spring.activiti.db-history-used=true
spring.activiti.async-executor-activate=true

Among them, the spring.activiti.database-schema-update attribute is used to automatically update the database schema, the spring.activiti.db-history-used attribute is used to enable database history, and the spring.activiti.async-executor-activate attribute is used to enable asynchronous Actuator.

6.3 Write process definition file

Create a folder named processes in the resources directory and create a file named myProcess.bpmn20.xml with the following content:


<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xmlns:xsd="http://www.w3.org/2001/XMLSchema"
             xmlns:activiti="http://activiti.org/bpmn"
             targetNamespace="Examples">

    <process id="myProcess" name="My Process">
        <startEvent id="startEvent" />
        <sequenceFlow id="flow1" sourceRef="startEvent" targetRef="task1" />
        <userTask id="task1" name="My Task" />
        <sequenceFlow id="flow2" sourceRef="task1" targetRef="endEvent" />
        <endEvent id="endEvent" />
    </process>

</definitions>

6.4 Writing startup class

Add the @EnableActiviti annotation in the main class, the code is as follows:


@SpringBootApplication
@EnableActiviti
public class ActivitiDemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(ActivitiDemoApplication.class, args);
    }

}

6.5 Running the application

Run the main class and the Activiti workflow engine will automatically deploy and start. You can use the Activiti API to operate workflows.

7. Summary

In summary, Activiti is a powerful, easy-to-use open source BPM framework suitable for enterprise-level applications of all sizes. By using Activiti, developers can quickly build efficient business processes and improve the organization's work efficiency and collaboration capabilities.

picture

Guess you like

Origin blog.csdn.net/weixin_40381772/article/details/133671913