微服务架构师封神之路12-Camunda工作流引擎实践 1

微服务架构师封神之路12-Camunda工作流引擎实践 1

  • pom.xml
  • application.yml
  • camunda配置文件,processes.xml
  • 启动类
  • 创建数据库
  • 启动应用
  • 参考资料
    • **罗小爬EX** 系列
    • 官方文档
    • camunda工具下载

Camunda BPM: BPM指Business Processing Model,业务流程建模工具,其实就是一个工作流引擎。并且它提供了一套图形化的业务流程设计工具来帮助业务人员建模。建模后的流程决策设计保存在.bpmn,.dmn,.cmmn文件中,可以方便的导入应用当中,直接使用。
我学习的原因是因为项目中的一个模块使用它来做流程控制,整体的业务流程执行效率有很大问题。不忽略每一个影响性能的因素,研究camunda就成了一道跳不过去的坎。

下面就直接上一个最简单的示例程序作为入门。
需求:

  • springboot应用
  • mysql数据库
  • camunda 7.18 (与springboot集成)

pom.xml

主要注意和camunda相关的4个应用,


<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0modelVersion>
    <groupId>com.b5wang.cloudlab.bpmgroupId>
    <artifactId>camundaexartifactId>
    <version>0.1-SNAPSHOTversion>
    <packaging>jarpackaging>

    <properties>
        <project.build.sourceEncoding>UTF-8project.build.sourceEncoding>
        <maven.compiler.source>1.8maven.compiler.source>
        <maven.compiler.target>1.8maven.compiler.target>
        <spring-boot.version>2.7.8spring-boot.version>
        <spring-cloud.version>2022.0.0spring-cloud.version>
        <log4j-1.2-api.version>2.13.3log4j-1.2-api.version>
        <camunda.version>7.18.0camunda.version>
    properties>

    <dependencies>
        
        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-webartifactId>
        dependency>
        <dependency>
            <groupId>org.projectlombokgroupId>
            <artifactId>lombokartifactId>
        dependency>
        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-testartifactId>
            <scope>testscope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintagegroupId>
                    <artifactId>junit-vintage-engineartifactId>
                exclusion>
            exclusions>
        dependency>
        
        
        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-jdbcartifactId>
        dependency>
        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-data-jpaartifactId>
        dependency>
        <dependency>
            <groupId>com.mysqlgroupId>
            <artifactId>mysql-connector-jartifactId>
            <version>8.0.32version>
        dependency>

        
        <dependency>
            <groupId>org.camunda.bpm.springbootgroupId>
            <artifactId>camunda-bpm-spring-boot-starterartifactId>
        dependency>
        <dependency>
            <groupId>org.camunda.bpm.springbootgroupId>
            <artifactId>camunda-bpm-spring-boot-starter-restartifactId>
        dependency>
        <dependency>
            <groupId>org.camunda.bpm.springbootgroupId>
            <artifactId>camunda-bpm-spring-boot-starter-webappartifactId>
        dependency>
        <dependency>
            <groupId>org.camunda.bpm.springbootgroupId>
            <artifactId>camunda-bpm-spring-boot-starter-external-task-clientartifactId>
        dependency>

    dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.bootgroupId>
                <artifactId>spring-boot-dependenciesartifactId>
                <version>${spring-boot.version}version>
                <type>pomtype>
                <scope>importscope>
            dependency>
            <dependency>
                <groupId>org.springframework.cloudgroupId>
                <artifactId>spring-cloud-dependenciesartifactId>
                <version>${spring-cloud.version}version>
                <type>pomtype>
                <scope>importscope>
            dependency>
            <dependency>
                <groupId>org.camunda.bpmgroupId>
                <artifactId>camunda-bomartifactId>
                <version>${camunda.version}version>
                <type>pomtype>
                <scope>importscope>
            dependency>
        dependencies>
    dependencyManagement>

    <build>
        <finalName>${project.artifactId}finalName>
        <plugins>
            <plugin>
                <groupId>org.springframework.bootgroupId>
                <artifactId>spring-boot-maven-pluginartifactId>
            plugin>
            <plugin>
                <groupId>org.apache.maven.pluginsgroupId>
                <artifactId>maven-site-pluginartifactId>
                <version>3.8.2version>
            plugin>
            <plugin>
                <groupId>org.apache.maven.pluginsgroupId>
                <artifactId>maven-project-info-reports-pluginartifactId>
                <version>3.0.0version>
            plugin>
        plugins>
    build>
project>

application.yml

server:
  port: 9090
spring:
  application:
    name: camundaex

  # 数据库配置
  datasource:
    type: com.zaxxer.hikari.HikariDataSource
    driverClassName: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/camundaex?useUnicode=true&characterEncoding=utf-8&useSSL=false
    username: root
    password: 111
    # Hikari 连接池配置
    hikari:
      # 最小空闲连接数量
      minimum-idle: 5
      # 空闲连接存活最大时间,默认600000(10分钟)
      idle-timeout: 180000
      # 连接池最大连接数,默认是10
      maximum-pool-size: 10
      # 此属性控制从池返回的连接的默认自动提交行为,默认值:true
      auto-commit: true
      # 连接池名称
      pool-name: HK-CP
      # 此属性控制池中连接的最长生命周期,值0表示无限生命周期,默认1800000即30分钟
      max-lifetime: 1800000
      # 数据库连接超时时间,默认30秒,即30000
      connection-timeout: 30000
      connection-test-query: SELECT 1

logging:
  level:
    com.zaxxer.hikari.HikariConfig: DEBUG
    com.zaxxer.hikari: TRACE

# camunda configuration
camunda.bpm:
  # 第一次启动时创建管理员
  admin-user:
    id: camunda
    password: camunda
    firstName: Camunda
  filter:
    create: All tasks

camunda配置文件,processes.xml

文件路径:resources/META-INF/processes.xml

<process-application
        xmlns="http://www.camunda.org/schema/1.0/ProcessApplication"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

    <process-archive name="camunda-process-engine">
        <process-engine>defaultprocess-engine>
        
        
        <properties>
            <property name="isDeleteUponUndeploy">falseproperty>
            <property name="isScanForProcessDefinitions">trueproperty>
        properties>
    process-archive>

process-application>

启动类

import org.camunda.bpm.spring.boot.starter.annotation.EnableProcessApplication;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
@EnableProcessApplication
public class AppStarter {

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

}

创建数据库

mysql创建一个空的schema, camundaex

drop schema if exists camundaex;
create schema if not exists camundaex;

启动应用

检查两个结果:

  • 所有和camunda相关的表会在第一次启动的时候创建好
  • 访问http://localhost:9090,使用用户camunda / camunda登录,它也是在第一次启动的时候根据application.yml中的设置创建好的

本文的源码:https://github.com/b5wang/cloudlab/tree/master/bpm/camundaex

参考资料

罗小爬EX 系列

Camunda入门(一) - 选型及核心概念
Camunda入门(二) - 启动Camunda管理平台
Camunda入门(三) - BPMN、DMN、Form相关模型介绍(持续补充…)
Camunda入门(四) - 流程应用(支付流程)入门示例
示例代码

官方文档

http://camunda-cn.shaochenfeng.com/
https://docs.camunda.org/get-started/
https://docs.camunda.io/
https://camunda.com/

camunda工具下载

https://camunda.com/download/

你可能感兴趣的:(微服务架构实践,spring,boot,java,后端)