来自云龙湖轮廓分明的月亮 发表于 2024-5-18 05:06:08

Camunda

Camunda

简介

Camunda是一个工作流引擎,实行Bpmn2.0标准。与它同范例的流程引擎有jbpm、activiti、flowable,但与Camunda相比,Camunda性能和稳定性都表现较好,更轻量级。
Camunda包括:流程设计器(Modeler)、流程引擎(Engine)、API接口(REST/Java API)、任务列表(TaskList)、流程管理控制台(Cockpit)、体系管理工具(Admin)。
详细介绍参考博客:https://blog.csdn.net/qq_41468822/article/details/135343266
示例demo下载: https://github.com/caohuajin/spring-boot-camunda.git
架构图

camunda团体架构如下图所示,重要包括两部分:流程建模工具(modeler)和流程引擎(Engine)。业务分析与开发职员(Business Analyst/Developer)通过modeler设计业务流程,将效果存入repository中,业务分析与开发职员一般不需要懂开发。流程引擎则负责流程实例的创建、实行、维护和管理,并通过REST/Java API向用户提供服务,基于这些API,流程用户(End User)通过Tasklist工具到场流程的实行,运维职员(operator)通过Cockpit工具查看、管理和维护流程的状态,管理职员(administrator)通过Admin工具进行用户的权限管理。当然,我们也可以基于REST/Java API开发自己的相应工具。通过下面的实例展示可知,camunda提供的tasklist、cockpit、admin工具非常有可能不是很符合你们团队的需求,需要自己开发部分功能。
https://img2024.cnblogs.com/blog/3109817/202404/3109817-20240419151845413-1429647576.png
BPMN概念

BPMN(Business Process Model and Notation)是一种用于描述业务流程的图形化标准。它提供了一种同一的方法来表示业务过程,使得业务分析师、业务用户和技术职员之间可以更好地沟通和理解业务流程。
以下是 BPMN 中的一些重要概念:

[*]流程(Process):流程是指业务中的一系列活动或任务,以实现特定的业务目标。在 BPMN 中,流程可以被建模成各种形式,包括业务流程、子流程和协作流程等。
[*]活动(Activity):活动是流程中的根本单元,代表实行的任务或操作。活动可以是一个简单的任务,也可以是一个复杂的子流程。
[*]变乱(Event):变乱是流程中的状态变革,可以触发或影响流程的实行。例如,开始变乱表示流程的开始,结束变乱表示流程的结束,中间变乱表示在流程实行过程中发生的中间状态。
[*]网关(Gateway):网关用于控制流程的分支、合并和路由。根据条件,网关可以决定流程的实行路径。
[*]序列流(Sequence Flow):序列流表示流程中活动之间的顺序关系,指示流程实行的方向。
[*]数据对象(Data Object):数据对象表示流程中使用的数据或信息。它可以是输入、输出或中间数据,用于支持流程的实行。
[*]泳道(Swimlane):泳道用于组织流程中的活动,可以按角色、部门或其他组织方式进行划分。泳道提供了对流程实行者的可视化描述。
BPMN 的这些概念可以资助用户以图形化的方式清晰地描述业务流程,从而更好地进行流程分析、优化和实行。
Camunda Modeler

用于创建、编辑和管理流程模型的软件工具。下载地址:https://camunda.com/download/modeler/
https://img2024.cnblogs.com/blog/3109817/202404/3109817-20240419152043846-1806128676.png
集成Spring boot

配置环境:

[*]jdk 17
[*]mysql latest
[*]camunda-bpm-spring-boot-starter 7.20.0
[*]spring-boot-starter-parent 3.2.3
application.yaml
spring:
application:
    name: camunda-demo
jersey:
    application-path: /engine-rest
datasource:
    driver-class-name: com.mysql.jdbc.Driver
    url: jdbc:mysql://127.0.0.1:3306/camunda_demo?allowPublicKeyRetrieval=true&useSSL=false&useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useOldAliasMetadataBehavior=true
    username: root
    password: root
camunda.bpm:
generic-properties:
    properties:
      enforceHistoryTimeToLive: false
admin-user:
    id: demo
    password: demo
    firstName: Demo
filter:
    create: All tasks
database:
    type: mysql
server:
port: 8080
tomcat:
    uri-encoding: UTF-8maven的pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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.0</modelVersion>

    <groupId>guru.springframework</groupId>
    <artifactId>spring-boot-camunda</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <parent>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-parent</artifactId>
      <version>3.2.3</version>
      <relativePath/>
    </parent>

    <name>spring-boot-camunda</name>
    <description>Demo project for Spring Boot and Camunda</description>

    <properties>
      <camunda.spring-boot.version>7.20.0</camunda.spring-boot.version>
      <maven.compiler.release>17</maven.compiler.release>
    </properties>

    <dependencies>
      <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.30</version>
      </dependency>
      <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
      </dependency>
      <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
      </dependency>
      <dependency>
            <groupId>org.camunda.bpm.springboot</groupId>
            <artifactId>camunda-bpm-spring-boot-starter</artifactId>
            <version>${camunda.spring-boot.version}</version>
      </dependency>
      <dependency>
            <groupId>org.camunda.bpm.springboot</groupId>
            <artifactId>camunda-bpm-spring-boot-starter-webapp</artifactId>
            <version>${camunda.spring-boot.version}</version>
      </dependency>
      <dependency>
            <groupId>org.camunda.bpm.springboot</groupId>
            <artifactId>camunda-bpm-spring-boot-starter-rest</artifactId>
            <version>${camunda.spring-boot.version}</version>
      </dependency>
      <dependency>
            <groupId>org.camunda.bpm.extension.swagger</groupId>
            <artifactId>camunda-bpm-swagger-json</artifactId>
            <version>7.8.0</version>
      </dependency>
      <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>swagger-ui</artifactId>
            <version>3.1.4</version>
      </dependency>
      <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.49</version>
      </dependency>
    </dependencies>
</project>常用web地址


[*]Swagger UI:http://localhost:8080/webjars/swagger-ui/3.1.4/index.html?docExpansion=none&url=/swagger.json#/
https://img2024.cnblogs.com/blog/3109817/202404/3109817-20240419152107294-759358995.png

[*]REST API: http://localhost:8080/engine-rest/
[*]Camunda web:http://localhost:8080/camunda/app/welcome/default/#!/welcome
https://img2024.cnblogs.com/blog/3109817/202404/3109817-20240419152114241-547579050.png
使用示例

基于JavaDelegate配置Camunda 的自动化服务节点

示例代码:
package guru.springframework.services.process;

import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.JavaDelegate;

public class TestDelegate implements JavaDelegate {
    @Override
    public void execute(DelegateExecution delegateExecution) throws Exception {
      System.out.println("TestDelegate: " + delegateExecution.getProcessInstanceId());
    }
}Modeler配置:
https://img2024.cnblogs.com/blog/3109817/202404/3109817-20240419152123602-339002089.png
基于ExecutionListener监听整个流程实行过程中的变乱

import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.ExecutionListener;

public class AmountApprovalDecisionListener implements ExecutionListener {
   
    @Override
    public void notify(DelegateExecution execution) throws Exception {
      double amount = (double) execution.getVariable("amount");
      execution.setVariable("amount", amount);
    }
}
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页: [1]
查看完整版本: Camunda