Flowable getting started series article 7 - basic configuration I

1. Create a ProcessEngine

The Flowable process engine is configured through an XML file named flowable.cfg.xml. Note that this does not apply if you use the Spring style of building a process engine.

The simplest method to obtain ProcessEngine is to use the org.flowable.engine.ProcessEngines class:

ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine()

This will find the file flowable.cfg.xml in the classpath and build the engine based on the configuration in the file. The following clip shows a sample configuration. The following sections describe the configuration properties in detail.

<beans xmlns="http://www.springframework.org/schema/beans"
<bean id="processEngineConfiguration" class="org.flowable.engine.impl.cfg.StandaloneProcessEngineConfiguration">
<property name="jdbcUrl" value="jdbc:h2:mem:flowable;DB_CLOSE_DELAY=1000" />
<property name="jdbcDriver" value="org.h2.Driver" />
<property name="jdbcUsername" value="sa" />
<property name="jdbcPassword" value="" />
<property name="databaseSchemaUpdate" value="true" />
<property name="asyncExecutorActivate" value="false" />
<property name="mailServerHost" value="mail.my-corp.com" />
<property name="mailServerPort" value="5025" />

Note that the configuration XML is actually a Spring configuration. This does not mean that Flowable can only be used in the Spring environment! We just use Spring's internal parsing and dependency injection capabilities to build the engine.

The ProcessEngineConfiguration object can also be created programmatically using a configuration file. You can also use different bean IDS (for example, see line 3).

createProcessEngineConfigurationFromResource(String resource);
createProcessEngineConfigurationFromResource(String resource, String beanName);
createProcessEngineConfigurationFromInputStream(InputStream inputStream);
createProcessEngineConfigurationFromInputStream(InputStream inputStream, String beanName);

You can also create a configuration based on default values without using a configuration file.


All of these ProcessEngineConfiguration.createXXX() methods return a ProcessEngineConfiguration, which can be further adjusted if necessary. call
After the buildProcessEngine() operation, ProcessEngine will create a:

ProcessEngine processEngine = ProcessEngineConfiguration.createStandaloneInMemProcessEngineConfiguration()

2,ProcessEngineConfiguration bean

Bean 'processEngineConfiguration' with ID must be included in flowable.cfg.xml.

<bean id="processEngineConfiguration" class="org.flowable.engine.impl.cfg.StandaloneProcessEngineConfiguration">

This bean is then used to construct the ProcessEngine. There are multiple classes available to define processEngineConfiguration. These classes represent different environments and set defaults accordingly
Value. The best practice is to select the class that best suits your environment to minimize the number of attributes required to configure the engine. The following courses are currently available:

  • org.flowable.engine.impl.cfg.StandaloneProcessEngineConfiguration: the process engine is used independently. Flowable will be responsible for all transactions. By default, the database is checked only when the engine starts (an exception is thrown if there is no flowable schema or the schema version is incorrect).
  • Org. Flowable. Engine. Impl. CFG. Standalonenmemprocessengineconfiguration: This is a convenient class for unit testing. Flowable will be responsible for all transactions. H2 memory database is used by default. The database is created and deleted when the engine starts and shuts down. When using this, no additional configuration may be required (except when using job executors or mail functions, for example).
  • org.flowable.spring.SpringProcessEngineConfiguration: used when using the process engine in the spring environment. For more information, see the spring integration section.
  • Org. Flowable. Engine. Impl. CFG. Jtaprocesengineconfiguration: JTA transactions are used when the engine is running in stand-alone mode.

3. Database configuration

There are two ways to configure the database that the Flowable engine will use. The first option is to define the JDBC properties of the database:

  • JDBC URL: the JDBC URL of the database.
  • JDBC Driver: a driver that executes a specific database type.
  • JDBC Username: the user name to connect to the database.
  • JDBC password: password to connect to the database.

Data sources built based on the provided JDBC properties will have the default MyBatis connection pool settings. You can choose to set the following properties to adjust the connection pool (from the MyBatis document):

  • JDBC maxactiveconnections: the maximum number of active connections that a connection pool can contain at any time. The default value is 10.
  • JDBC maxidleconnections: the maximum number of free connections that a connection pool can contain at any time.
  • JDBC maxcheckouttime: the amount of time (in milliseconds) that a connection can be checked out from the connection pool before forcing a return of the connection. The default is 20000 (20 seconds).
  • jdbcMaxWaitTime: This is a low-level setting that gives the pool the opportunity to print the log status and try to get the connection again to prevent abnormal long-term use (to avoid that if the pool is misconfigured, it will never fail in obscurity). The Default is 20000 (20 seconds).

Sample database configuration:

<property name="jdbcUrl" value="jdbc:h2:mem:flowable;DB_CLOSE_DELAY=1000" />
<property name="jdbcDriver" value="org.h2.Driver" />
<property name="jdbcUsername" value="sa" />
<property name="jdbcPassword" value="" />

Our benchmark shows that MyBatis connection pool is not the most efficient or flexible when dealing with a large number of concurrent requests. Therefore, it is recommended to give us a javax.sql.DataSource implementation and inject it into the process engine configuration (such as DBCP, C3P0, Hikari, Tomcat connection pool, etc.):

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" >
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/flowable" />
<property name="username" value="flowable" />
<property name="password" value="flowable" />
<property name="defaultAutoCommit" value="false" />
<bean id="processEngineConfiguration" class="org.flowable.engine.impl.cfg.StandaloneProcessEngineConfiguration">
<property name="dataSource" ref="dataSource" />

Note that Flowable does not ship with libraries that allow you to define such data sources. So you need to make sure that the library is in your classpath.

Whether you use JDBC or data source methods, you can set the following properties:

  • databaseType: this property does not usually need to be specified because it is automatically detected from the database connection metadata. Should only be specified when automatic detection fails. Possible values:
    {h2,mysql,oracle,postgres,mssql,db2}. This setting determines which create / delete scripts and queries to use. See the supported databases section for an overview of what types of support are used.
  • Database schemaupdate: set policies to handle the database schema when the process engine starts and shuts down.
    • false (default): checks the version of the database schema when creating the process engine and throws an exception when the version does not match.
    • true: when building the process engine, checks will be performed and schema updates will be performed if necessary. If the schema does not exist, it is created.
    • Create drop: creates a pattern when the process engine is created, and deletes the pattern when the process engine is shut down.

The above article is from Pangu BPM Research Institute: http://vue.pangubpm.com/
Article translation submission: https://github.com/qiudaoke/flowable-userguide
For more articles, you can focus on WeChat official account:

Tags: Java Flowable oa bpm

Posted on Mon, 27 Sep 2021 00:36:26 -0400 by xX_SuperCrazy_Xx