首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

俯瞰工作流Activiti-引擎配置

在开源工作流流程引擎Activiti的过程中,有很多参数是可配置的,例如数据库配置、事务配置、流程引擎内置服务配置等,Activiti通过流程引擎配置对象封装这些配置。本文对Activiti流程引擎的配置进行比较详细的介绍,让读者对各个配置项有深入的理解。

1.流程引擎配置对象

流程引擎配置对象ProcessEngineConfiguration里面有Activiti流程引擎里面的全部配置,为这些可配置的引擎属性提供对是对应的setter合getter方法。该类还提供了很多创建流程引擎配置对象ProcessEngineConfiguration实例的静态方法,这些方法会读取解析配置属性,然后返回对象的实例。该类是一个抽象类,实现类的类图结构如下图。

ProcessEngineConfiguration代表流程引擎的一个配置实例,由于ProcessEngineConfiguration是一个抽象类,我们就要用它的子类去创建bean。官方文档给出了每个实现类的作用。

This bean is then used to construct the . There are multiple classes available that can be used to define the processEngineConfiguration. These classes represent different environments, and set defaults ccordingly. It’s a best practice to select the class the matches (the most) your environment, to minimalise the number of properties needed to configure the engine. The following classes are currently available (more will follow in future releases):

org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration:the process engine is used in a standalone way. Activiti will take care of the transactions. By default, the database will only be checked when the engine boots (and an exception is thrown if there is no Activiti schema or the schema version is incorrect).

org.activiti.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration:this is a convenience class for unit testing purposes. Activiti will take care of the transactions. An H2 in-memory database is used by default. The database will be created and dropped when the engine boots and shuts down. When using this, probably no additional configuration is needed (except when using for example the job executor or mail capabilities).

org.activiti.spring.SpringProcessEngineConfiguration:To be used when the process engine is used in a Spring environment.

org.activiti.engine.impl.cfg.JtaProcessEngineConfiguration:To be used when the engine runs in standalone mode, with JTA transactions.

org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration:应用在独立的环境中。 Activiti将会管理事务。默认情况下,只有在引擎启动时才会检查数据库(没有找到数据库或者错误的版本都会抛出异常)。

org.activiti.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration:这个类的目的是为了更方便单元测试。Activiti也会管理事务。默认就使用内存数据库H2。在流程引擎启动或者结束的时候会对应创建和删除数据库。不需要进行额外的配置。(除非使用工作执行器和或者邮件功能)。

org.activiti.spring.SpringProcessEngineConfiguration:用于与spring整合。

org.activiti.engine.impl.cfg.JtaProcessEngineConfiguration:用于独立环境中,使用JTA事务。

2.数据库配置

Activiti使用两种数据库配置方式,第一种是直接用JDBC日的属性进行配置。

jdbcUrl: JDBC URL。

jdbcDriver:不同数据库类型的驱动。

jdbcUsername: 用户名。

jdbcPassword: 密码。

第二种是用Mybatis的连接池配置,下面这些属性引用的是mybaits的文档。

jdbcMaxActiveConnections: 最大活跃连接数,默认10。

jdbcMaxIdleConnections: 最大空闲连接数。

jdbcMaxCheckoutTime: 心跳检查,连接被取出使用的最长时间,超过时间会被强制回收。默认20000(20s)。

jdbcMaxWaitTime: 最大等待时间。默认20000(20s)。官方解释如下:

This is a low level setting that gives the pool a chance to print a log status and re-attempt the acquisition of a connection in the case that it is taking unusually long (to avoid failing silently forever if the pool is misconfigured) Default is 20000 (20 seconds).

下面是一个数据库配置举例:

我们都知道,当我们处理更多的连接请求,Mybatis连接池并不是最有效和恢复比较好的。所以官方建议使用javax.sql.DataSource 的实现类注入到我们的流程引擎中。 (例如 DBCP, C3P0, Hikari, Tomcat Connection Pool等)。

注意:Activit并没有并没有将这些数据源集成,所以我们需要确保我的的classpath有这些数据源的类库。

不管是使用JDBC配置还是数据源,下面两个属性都可以配置:

databaseType: 数据库类型并不需要特别的去指定,从数据库连接的元数据可以自动识别数据库类型,仅仅当自动识别失败才需要配置该属性。可选的值有:. 这个设置会决定哪种数据库脚本将会被执行,支持的数据库类型如下。

databaseSchemaUpdate: 该属性可以设置流程引擎启动和关闭时数据库执行的策略:

false (默认值): 流程引擎启动时检查数据库表中的的版本,如果没有表或者版本不匹配,抛出异常。

true: 引擎启动时,自动更新表,表不存在车自动创建。

create-drop: 引擎启动是创建数据库,引擎关闭时删除数据库。

3.任务执行器配置(Activiti6.0+)

属性主要用于配置异步执行器是否启动,true则表示Activiti在创建路程引擎时,需要启动异步执行器,该属性的默认值为false。异步执行器启动后,会启动定时器扫描并执行各种工作。

4.邮件服务配置

5.历史数据配置

在流程执行的过程中,会产生一些流程相关的数据,例如流程实例、流程任务和流程参数等,随着流程的结束,这些数据会从运行时数据表删除,并且保存到历史数据表。历史数据的保存可以设置不同的级别,Activiti提供了history属性对保存历史数据的级别进行配置。有点类似平时使用的日子级别,history提供了是个选项:

none:不保存任何值,效率高,但是历史数据一点都不保存。

activiti:高于none级别,保存流程实例与流程行为,其他数据不保存。

audit:默认级别,出去activiti级别的数据会保存外,还会保存全部的流程任务以及其属性数据。

full:最高级别,出去前面级别保存的,还会把偶才能其他全部流程相关的细节数据,包括一些流程参数等。

本文讲述了Activiti流程引擎的一些常用配置,并且分析了这些配置在流程引擎中的一些具体作用,同时也讲述了ProcessEngineConfiguration的bean配置。这些配置是流程引擎的基础,掌握了这些配置知识后,可以创建与具体业务更加贴近的个性化流程引擎。

参考网址:https://www.activiti.org/userguide/参考书籍:>

  • 发表于:
  • 原文链接https://kuaibao.qq.com/s/20181002G0TY8W00?refer=cp_1026
  • 腾讯「腾讯云开发者社区」是腾讯内容开放平台帐号(企鹅号)传播渠道之一,根据《腾讯内容开放平台服务协议》转载发布内容。
  • 如有侵权,请联系 cloudcommunity@tencent.com 删除。

扫码

添加站长 进交流群

领取专属 10元无门槛券

私享最新 技术干货

扫码加入开发者社群
领券