应用开发平台集成工作流——工作流引擎集成实战

集成模式

Camunda支持三种引擎模式的特点如下:

  1. Container-managed Engine:流程引擎会作为一个独立的组件运行在JVM中,由CAMUNDA容器管理,也就是官方自带了一套管理系统。
  2. Embedded Engine:流程引擎会嵌入到你的应用中,由应用直接管理,因此可以获得更好的控制和性能。
  3. Remote Engine:流程引擎会作为一个独立的组件运行在另一个JVM中,作为远程BPM服务器运行,通过RMI或HTTP通信与远程引擎交互。

第一种方式实际是大型功能组件的通用做法,即不仅有核心功能,还附加了管理、监控等辅助功能,形成一套能独立运行的系统,达到开箱即用的目的。
第三种方式是作为独立服务运行,相当于浅度集成,只通过rest api来调用,适用于非java技术栈(如c#)或微服务架构,保持相对独立。
第二种方式则是常说的深度集成,将引擎内嵌到应用程序内部,从而性能最好,控制性更强,可直接调用本地java方法,并且可以直接访问Camunda的库表,面向一些复杂业务的情况,编写sql语句进行连表查询或数据写入。

综上,平台集成采用了是第二种模式,深度集成。

初始化

新建模块

首先新建功能模块,遵循平台统一命名规则,命名为platform-workflow,继承自平台

<parent>
  <groupId>tech.abc</groupId>
  <artifactId>abc-development-platform</artifactId>
  <version>2.0.0</version>
</parent>
<groupId>tech.abc</groupId>
<artifactId>platform-workflow</artifactId>
<packaging>jar</packaging>
<version>2.0.0</version>
<name>platform-workflow</name>
<description>工作流</description>

修改工程的pom文件,将该模块纳入到工程中

<modules>
      <module>platform-common</module>
      <module>platform-system</module>
      <module>platform-framework</module>
      ……
       <!--本次新增-->
      <module>platform-workflow</module>
      ……
      <module>platform-boot-starter</module>
     
  </modules>

添加依赖

查了下当前最新的版本,是7.19,三年前集成时使用的7.13,版本差距不大,使用最新版本,添加对Camunda的依赖,

<!-- 工作流 -->
<dependency>
    <groupId>org.camunda.bpm.springboot</groupId>
    <artifactId>camunda-bpm-spring-boot-starter</artifactId>
    <version>7.19.0</version>
</dependency>

工作流中会涉及到部门人员用户组等,添加对platform-system模块的依赖

<dependency>
    <groupId>tech.abc</groupId>
    <artifactId>platform-system</artifactId>
</dependency>

解决冲突

分析pom,发现jar包冲突
image.png
考虑到一方面优先使用更新版本,另一方面mybatis-plus影响面更广,因此使用了排除exclusions

<!-- 工作流 -->
<dependency>
    <groupId>org.camunda.bpm.springboot</groupId>
    <artifactId>camunda-bpm-spring-boot-starter</artifactId>
    <version>7.19.0</version>
    <exclusions>
        <exclusion>
            <artifactId>mybatis</artifactId>
            <groupId>org.mybatis</groupId>
        </exclusion>
    </exclusions>
</dependency>

纳入启动

修改聚合项目platform-boot-starter的pom文件,将workflow模块加入进去,从而使工作流引擎随系统启动开始运行。

<dependencies>
    <dependency>
        <groupId>tech.abc</groupId>
        <artifactId>platform-framework</artifactId>
    </dependency>
    <dependency>
        <groupId>tech.abc</groupId>
        <artifactId>platform-entity-config</artifactId>
    </dependency>
    <dependency>
        <groupId>tech.abc</groupId>
        <artifactId>platform-cip-api</artifactId>
    </dependency>
    <dependency>
        <groupId>tech.abc</groupId>
        <artifactId>platform-cip-message</artifactId>
    </dependency>
    <dependency>
        <groupId>tech.abc</groupId>
        <artifactId>platform-workflow</artifactId>
    </dependency>
</dependencies>

添加配置

修改platform-boot-starter的配置文件application-platform.yml

#工作流配置
camunda:
  bpm:
    database:
      type: mysql
      schema-update: true

重点是database节点,type指定数据库类型是mysql,schema-update有四种取值:

  1. false:默认值,在启动时对比数据库表中保存的版本,如果没有表或者版本不匹配,将抛出异常。
  2. true:会对数据库中所有表进行更新操作。如果表不存在,则自动创建。
  3. create_drop:在activiti启动时创建表,在关闭时删除表(必须手动关闭引擎,才能删除表)。
  4. drop-create:在activiti启动时删除原来的旧表,然后在创建新表(不需要手动关闭引擎)。

第1种是只做检查,不做处理,通常用于生产环境;后面三种用于开发环境,3和4相当于自动恢复成初始环境状态。
通常在第一次运行时,将该值设置为true,目的在于自动生成库表,然后将值调整为false,去除检查,加快启动速度。

运行

启动springboot,从输出日志可以看到,camunda已经加载了,并且红框部分也显示,调用了初始化sql脚本,创建了库表
image.png
查看数据库,自动创建了49张表(下图为部分库表,不全)
image.png

开发平台资料

平台名称:一二三开发平台
简介: 企业级通用开发平台
设计资料:csdn专栏
开源地址:Gitee
开源协议:MIT
开源不易,欢迎收藏、点赞、评论。

猜你喜欢

转载自blog.csdn.net/seawaving/article/details/131668334