This article is a personal learning summary, mainly summarizes the functions of several core Api and common configuration description.

Like friends can click a subscription, we learn progress together.

What is Activiti

Activiti is an open source framework for business process management that supports the BPMN2.0 process definition protocol. Its main functions include process definition, process deployment, process execution, user group management, historical record query and other functions. The more complex the business, the more the need for process management tools, Activiti is a good choice, from oa system approval to e-commerce system shopping, these complex business scenarios can be seen in Activiti. When hard-coding a complex business, every step of the flow judgment is fraught with risk, the wrong results can be lost, and problems can be difficult to track down. When writing a complex business based on Activiti, you can draw a process definition file to make the business visible at a glance, greatly reducing the probability of a complex business failure. The rest is left to Activiti, which will strictly follow the process definition.

Why Activiti

  1. Actitvti supports the BPMN2.0 process definition protocol.
  2. Activiti is very easy to integrate with Spring, even Starter, and SpringBoot is even easier to integrate with.
  3. Activiti’s community is active, github submissions are frequent, and developers are constantly adding to it.
  4. Activiti provides a rich API that can be used for most business scenarios.

Activiti core Api

Activiti provides consumers with a number of interfaces for everything from process deployment, process execution, and historical process record lookup. There are seven main apis:

  1. RepositoryService deploys the process definition file and manages the process definition instances.
  2. RuntimeService, the main function, starts the process, manages the process instance, sets and retrieves the process variable.
  3. TaskService: Processes tasks, sets task candidates (groups), specifies task handlers (groups), and sets attachments.
  4. FormService: obtains the form data of a task, submits a task to complete, and starts a process.
  5. HistoryService: queries process history records, event records, and variable records.
  6. Create users, create groups, and query users or groups.
  7. ManagementService, mainly used to execute custom commands, query underlying entities, data tables, and provide more extended functions.

Activiti configuration Description

The following configuration is an XML file for integration with Spring. If SpingBoot is integrated, the corresponding beans can also be configured in the SpringBoot project based on annotations. You can also integrate activiti’s implementation Starter, where the project automatically assembles common beans from YML files, providing a core API.

<? xml version="1.0" encoding="UTF-8"? > <beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

  <bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration"> <! -- Set the data source, specify the data source bean configured in the project --> <property name="dataSource" ref="dataSource"/ > <! -- Set the update policy for the project startup database table --> <! --flase: default value. When Activiti starts, it compares versions saved in database tables and throws an exception if there are no tables or versions do not match. -- > <! --true: Activiti updates all tables in the database. If the table does not exist, it is created automatically. -- > <! -- CREATE_DROP: Create tables when Activiti is started and drop tables when activiti is shut down (you must manually shut down the engine to drop tables). -- > <! --drop-create: Drop old tables when Activiti starts, and then create new tables (no need to manually shut down the engine). --> <property name="databaseSchemaUpdate" value="true"/ > <! -- prefix all table names --> <! --<property name="databaseTablePrefix" value="t_"/ > -- > <! -- Specify the database type --> <property name="databaseType" value="mysql"/ > <! -- Configure the level of history preservation --> <! -- None: No historical data is saved, so this is most efficient during process execution. -- > <! -- Activity: A level higher than None saves the process instance and process behavior. Other data is not saved. -- > <! -- AUDIT: All process tasks and their properties will be saved in addition to the data stored at the activity level. Audit forhistoryThe default value of. -- > <! -- Full: Stores the highest level of historical data. In addition to audit level data, it also stores all other details related to processes, including some process parameters. --> <property name="history" value="full"/ > <! -- Configure whether to use the history-related table --> <property name="dbHistoryUsed" value="true"/ > <! -- Configure whether to use the user permission related table --> <property name="dbIdentityUsed" value="true"/ > <! -- Configure a custom command interceptor, executed before configuring the default interceptor --> <property name="customPreCommandInterceptors"> <list> <! - interceptor needs to implement AbstractCommandInterceptor abstract classes - > < bean class ="com.fbl.activiti6spring.interceptor.ExecutionTimeInterceptor"/> </list> </property> <! -- Configure custom command interceptor, execute after configuring to default interceptor --> <property name="customPostCommandInterceptors">
      <list>
        <bean class="com.fbl.activiti6spring.interceptor.ExecutionTimeInterceptor"/> </list> </property> <! -- Set whether to enable the asynchronous execution function. After enabling this function, the flow can be started periodically. --> <property name="asyncExecutorActivate" value="true"/ > <! -- Set the thread pool for asynchronous tasks --> <property name="asyncExecutor">
      <bean class="org.activiti.engine.impl.asyncexecutor.DefaultAsyncJobExecutor"> <! ExecutorService bean --> <property name="executorService" ref="executorService"/> </bean> </property> <! Configure custom event listeners. In Activiti, there are many events that are monitored by listeners when they occur, such as process start time and process end events. Can also be a custom event, runtimeService dispatchEvent () manually issue an event -- > < property name ="eventListeners"> <list> <! The Event listener implements the ActivitiEventListener interface --> < Bean class="com.fbl.activiti6spring.event.ProcessInstanceEventListener"/>
        <bean class="com.fbl.activiti6spring.event.CustomEventListener"/> </list> </property> <! PROCESS_STARTED is the process start event --> <! --<property name="typedEventListeners"> -- > <! -- <map>--> <! -- <entry key="PROCESS_STARTED"> -- > <! -- <bean class="com.fbl.activiti.activitidome.event.ProcessInstanceEventListener"/ > -- > <! -- </entry>--> <! -- </map>--> <! --</property>--> <! -- Configure transaction manager --> <property name="transactionManager" ref = "transactionManager"/>

  </bean>


  <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
    <property name="url" value="JDBC: mysql: / / 127.0.0.1:3306 / activiti6? useSSL=false& characterEncoding=UTF-8" />
    <property name="driverClassName" value="com.mysql.jdbc.Driver" />
    <property name="username" value="root" />
    <property name="password" value="1234" />
    <property name="initialSize" value="1" />
    <property name="maxActive" value="10" />
    <property name="filters" value="stat,slf4j"/> </bean> <! -- Configure Spring transaction manager --> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dataSource"/> </bean> <! -- Configure thread pool to provide environment for asynchronous task execution --> <bean id="executorService" class="org.springframework.scheduling.concurrent.ThreadPoolExecutorFactoryBean">
    <property name="threadNamePrefix" value="activiti_"/>
    <property name="corePoolSize" value="5" />
    <property name="maxPoolSize" value="10" />
    <property name="queueCapacity" value="20" />
    <property name="rejectedExecutionHandler">
      <bean class="java.util.concurrent.ThreadPoolExecutor$AbortPolicy"/> </property> </bean> <! Create the process core Api factory Bean --> < Bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
    <property name="processEngineConfiguration" ref="processEngineConfiguration"/> </bean> <! -- Register activiti's test Rule with the container --> <bean id="activitiRule" class="org.activiti.engine.test.ActivitiRule"> <! --<property name="processEngineConfiguration" ref="processEngineConfiguration"/>-->
    <property name="processEngine" ref="processEngine"/> </bean> <! Register the Activiti core Api you want to use with the container --> <bean id="runtimeService" factory-bean="processEngine" factory-method="getRuntimeService"/>
  <bean id="formService" factory-bean="processEngine" factory-method="getFormService"/>
  <bean id="taskService" factory-bean="processEngine" factory-method="getTaskService"/>
  <bean id="helloWordServices" class="com.fbl.activiti6spring.services.HelloWordServices" />

</beans>
Copy the code