SpringBoot整合Activiti7——错误事件(十一)

news2025/2/26 21:59:05

文章目录

  • 错误事件
    • 开始事件
    • 边界事件
    • 结束事件
    • 代码实现
      • 开始事件
        • xml文件
        • 测试流程
        • 流程执行步骤
      • 边界与结束事件
        • xml文件
        • 自定义错误监听器
        • 测试流程
        • 流程执行步骤


错误事件

好像都是中断的。非中断没测出来!!!

<!-- 定义错误 -->
<error id="error1" name="errorCode1" errorCode="123456"/>
<error id="error2" name="errorCode2" errorCode="123456"/>

开始事件

开始事件只能在事件子流程中被触发,也不能用于启动流程,总是中断的。

可以用于捕获工作流启动时可能出现的各种错误情况,并根据具体的业务需求进行相应的处理。

<!-- 错误开始事件 -->
<startEvent id="sid-9f66c2ee-3281-486e-9aea-e27f29dad682" name="错误开始事件">
  <!-- 引用错误码 -->
  <errorEventDefinition errorRef="error1"/>
</startEvent>

边界事件

总是用于用户任务或子流程上。

当某个任务发生错误时,可以通过错误边界事件来捕获并处理该错误,以保证流程的正常执行。

<!-- 错误边界事件1 非中断 -->
<boundaryEvent id="sid-ef65efec-11aa-4c72-98c5-3cc42a2a8229" attachedToRef="sid-7f48d1e2-a7e5-4717-ad18-cbc5a78b8113" cancelActivity="false" name="错误边界事件1">
  <!-- 引用错误码 -->
  <errorEventDefinition errorRef="error1"/>
</boundaryEvent>

结束事件

错误结束事件就是流程抛出一个bpmn错误。然后被工作流的错误边界事件获取。

错误结束事件会在流程到达错误结束事件的时候抛出错误,并结束当前的流程分支。错误可以使用匹配的错误边界事件捕获。如果找不到匹配的错误边界事件,将会抛出异常。

<!-- 错误结束事件 -->
<endEvent id="sid-1600e3d8-61f9-428f-82c8-c048ef84c774" name="错误结束事件">
  <!-- 引用错误码 -->  
  <errorEventDefinition errorRef="error1"/>
</endEvent>

代码实现

开始事件

错误开始事件针对某个事件子流程触发。(虚线子流程框)
在这里插入图片描述

xml文件
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/processdef">
  <!-- 定义错误 -->
  <error id="error1" name="errorCode1" errorCode="123456"/>
  <process id="error-start" name="错误开始事件" isExecutable="true">
    <documentation>错误开始事件流程</documentation>
    <!-- 开始事件 -->
    <startEvent id="sid-0347a044-9d2e-465b-a449-eb6699044ae4" name="开始事件"/>
    <!-- 服务任务1抛出异常 -->
    <serviceTask id="sid-8accfa7d-4feb-4d3d-8088-bd2df124b57a" activiti:exclusive="true" name="服务任务1" activiti:delegateExpression="${myThrowErrorDelegateListener}"/>
    <!-- 结束事件 -->
    <endEvent id="sid-2efe3807-4285-416c-a2b7-c3827ec433d2" name="结束事件"/>
    <!-- 子流程 triggeredByEvent表示被事件触发 -->
    <subProcess id="sid-9405baaf-73a2-4f6d-8c17-3ce20b221bbe" triggeredByEvent="true" activiti:exclusive="true">
      <!-- 错误开始事件 -->
      <startEvent id="sid-9f66c2ee-3281-486e-9aea-e27f29dad682" name="错误开始事件">
        <!-- 引用错误码 -->
        <errorEventDefinition errorRef="error1"/>
      </startEvent>
      <!-- 子流程服务任务 -->
      <serviceTask id="sid-1b0e1eec-d26b-4a7a-94b3-8e8b5970b3fa" activiti:exclusive="true" name="子流程服务任务" activiti:delegateExpression="${myServiceTaskListener}"/>
      <!-- 子流程结束事件 -->
      <endEvent id="sid-35fbe381-270f-4ade-bf1b-1e32c289f946" name="子流程结束事件"/>
      <sequenceFlow id="sid-36a022c4-ff28-44f7-8694-b23cf7592b68" sourceRef="sid-1b0e1eec-d26b-4a7a-94b3-8e8b5970b3fa" targetRef="sid-35fbe381-270f-4ade-bf1b-1e32c289f946"/>
      <sequenceFlow id="sid-3ff4163b-067d-4e9b-8e26-ad05a1c9d7a2" sourceRef="sid-9f66c2ee-3281-486e-9aea-e27f29dad682" targetRef="sid-1b0e1eec-d26b-4a7a-94b3-8e8b5970b3fa"/>
    </subProcess>
    <sequenceFlow id="sid-3747e8f1-b5c6-4b83-b8af-c74038303170" sourceRef="sid-8accfa7d-4feb-4d3d-8088-bd2df124b57a" targetRef="sid-2909cd9a-c18a-429b-be89-4543b6524bbc"/>
    <sequenceFlow id="sid-b3c67896-5be8-4c59-b046-4c4affb36555" sourceRef="sid-0347a044-9d2e-465b-a449-eb6699044ae4" targetRef="sid-8accfa7d-4feb-4d3d-8088-bd2df124b57a"/>
    <!-- 服务任务2 -->
    <serviceTask id="sid-2909cd9a-c18a-429b-be89-4543b6524bbc" activiti:exclusive="true" name="服务任务2" activiti:delegateExpression="${myServiceTaskListener}"/>
    <sequenceFlow id="sid-bff0ca04-cd48-4aa9-8405-66e63124e59b" sourceRef="sid-2909cd9a-c18a-429b-be89-4543b6524bbc" targetRef="sid-2efe3807-4285-416c-a2b7-c3827ec433d2"/>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_error">
    <bpmndi:BPMNPlane bpmnElement="error-start" id="BPMNPlane_error">
      <bpmndi:BPMNShape id="shape-8d5f52a3-a6a2-4f64-9efb-e9837679722e" bpmnElement="sid-0347a044-9d2e-465b-a449-eb6699044ae4">
        <omgdc:Bounds x="-235.35788" y="16.2278" width="30.0" height="30.0"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="shape-486bc80b-61bf-464f-be0f-a586c65eb86e" bpmnElement="sid-9405baaf-73a2-4f6d-8c17-3ce20b221bbe">
        <omgdc:Bounds x="-217.49924" y="92.053925" width="221.21466" height="121.94145"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="shape-f95a940b-f150-49f8-9d86-09923329f6d0" bpmnElement="sid-1b0e1eec-d26b-4a7a-94b3-8e8b5970b3fa">
        <omgdc:Bounds x="-157.19922" y="114.25392" width="100.0" height="80.0"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="shape-08ea584c-b113-4d02-9d65-156a6fb35a50" bpmnElement="sid-35fbe381-270f-4ade-bf1b-1e32c289f946">
        <omgdc:Bounds x="-35.8492" y="139.25392" width="30.0" height="30.0"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge id="edge-993acd65-bf4f-4337-96d4-eb6c5ce1fdab" bpmnElement="sid-36a022c4-ff28-44f7-8694-b23cf7592b68">
        <omgdi:waypoint x="-57.19922" y="154.25392"/>
        <omgdi:waypoint x="-35.8492" y="154.25392"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNShape id="shape-07af35b3-f623-4fdd-99ae-675c6c7894e6" bpmnElement="sid-2efe3807-4285-416c-a2b7-c3827ec433d2">
        <omgdc:Bounds x="105.030174" y="16.227798" width="30.0" height="30.0"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="shape-bae0f412-1c38-4baf-a8d8-a4740dc0c63e" bpmnElement="sid-8accfa7d-4feb-4d3d-8088-bd2df124b57a">
        <omgdc:Bounds x="-156.8919" y="-8.7722" width="100.0" height="80.0"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge id="edge-b07f91be-b837-448d-a8a7-0892ac5b39a2" bpmnElement="sid-3747e8f1-b5c6-4b83-b8af-c74038303170">
        <omgdi:waypoint x="-56.891907" y="31.2278"/>
        <omgdi:waypoint x="-23.466818" y="31.227797"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNShape id="shape-f2b44140-d7d8-4110-8001-8eb61b3ae601" bpmnElement="sid-9f66c2ee-3281-486e-9aea-e27f29dad682">
        <omgdc:Bounds x="-207.4492" y="139.25392" width="30.0" height="30.0"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge id="edge-26b2554a-e5f0-4b44-a70a-00b3ff5812be" bpmnElement="sid-3ff4163b-067d-4e9b-8e26-ad05a1c9d7a2">
        <omgdi:waypoint x="-177.4492" y="154.25392"/>
        <omgdi:waypoint x="-157.19922" y="154.25392"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="edge-ea9c91b4-9a2b-4e63-bba6-4f36d68c4f81" bpmnElement="sid-b3c67896-5be8-4c59-b046-4c4affb36555">
        <omgdi:waypoint x="-205.35788" y="31.2278"/>
        <omgdi:waypoint x="-156.8919" y="31.2278"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNShape id="shape-f8f20ee5-036e-492f-b7af-33dde9d12290" bpmnElement="sid-2909cd9a-c18a-429b-be89-4543b6524bbc">
        <omgdc:Bounds x="-23.466816" y="-8.772202" width="100.0" height="80.0"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge id="edge-004bd7a2-8a83-4bb1-a732-2afcd4bf131e" bpmnElement="sid-bff0ca04-cd48-4aa9-8405-66e63124e59b">
        <omgdi:waypoint x="76.53319" y="31.227798"/>
        <omgdi:waypoint x="105.030174" y="31.227798"/>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>
测试流程
@Test
public void deployAndStartProcessByErrorStart() {
    // 部署流程
    Deployment deploy = repositoryService.createDeployment()
            .addClasspathResource("processes/error-start.bpmn20.xml")
            .deploy();
    System.out.println("deploy = " + deploy);

    // 启动流程
    String processDefinitionKey = "error-start";
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(processDefinitionKey, processDefinitionKey + ":100001");
    System.out.println("processInstance = " + processInstance);
}
流程执行步骤
// 1.部署并启动流程
// 2.触发服务任务,服务任务监听器抛出异常,错误码errorCode
// 3.子流程接收到错误码为errorCode,触发错误开始事件
// 4.触发子流程服务任务
// 5.结束流程

边界与结束事件

流程图设计一个子流程,然后子流程里面有一个错误结束事件。外面的错误捕获边界任务就会捕获异常。捕获了异常后由于是错误边界先去捕获异常,所以捕获错误事件分支会先执行,然后结束。正常结束事件节点所在的分支不会执行。

开始 - 子流程开始 - 排他网关 - 错误结束事件 - 错误边界事件 - 结束流程
在这里插入图片描述

xml文件
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/processdef">
  <!-- 定义错误 -->
  <error id="error1" name="errorCode1" errorCode="123456"/>
  <process id="error-boundary-end" name="错误边界与结束事件" isExecutable="true">
    <documentation>错误边界与结束事件</documentation>
    <!-- 开始事件 -->
    <startEvent id="sid-0347a044-9d2e-465b-a449-eb6699044ae4" name="开始事件"/>
    <!-- 子流程 -->
    <subProcess id="sid-9405baaf-73a2-4f6d-8c17-3ce20b221bbe" activiti:exclusive="true">
      <!-- 子流程开始事件 -->
      <startEvent id="sid-9f66c2ee-3281-486e-9aea-e27f29dad682" name="子流程开始事件"/>
      <!-- 子流程服务任务抛出异常 -->
      <!-- 子流程结束事件 -->
      <sequenceFlow id="sid-3ff4163b-067d-4e9b-8e26-ad05a1c9d7a2" sourceRef="sid-9f66c2ee-3281-486e-9aea-e27f29dad682" targetRef="sid-1b0e1eec-d26b-4a7a-94b3-8e8b5970b3fa"/>
      <!-- 保存信息任务 -->
      <userTask id="sid-1b0e1eec-d26b-4a7a-94b3-8e8b5970b3fa" name="保存信息任务" activiti:assignee="${assignee}">
        <extensionElements>
          <activiti:taskListener event="create" delegateExpression="${myUserTaskListener}"/>
        </extensionElements>
      </userTask>
      <!-- 排他网关 -->
      <exclusiveGateway id="sid-8a8b73a7-b4ac-49f7-b572-c1cb77be5734"/>
      <!-- 保存成功 -->
      <endEvent id="sid-216515ff-91cb-4ec3-8d1e-c36a128f2dbf" name="保存成功"/>
      <!-- 错误结束事件 -->
      <endEvent id="sid-1600e3d8-61f9-428f-82c8-c048ef84c774" name="错误结束事件">
        <!-- 引用错误码 -->
        <errorEventDefinition errorRef="error1"/>
      </endEvent>
      <sequenceFlow id="sid-bfbfcc21-b6db-4275-9726-0560d0c397dd" sourceRef="sid-1b0e1eec-d26b-4a7a-94b3-8e8b5970b3fa" targetRef="sid-8a8b73a7-b4ac-49f7-b572-c1cb77be5734"/>
      <sequenceFlow id="sid-82b537d9-8377-4d7a-a3e1-7d204afe45dd" sourceRef="sid-8a8b73a7-b4ac-49f7-b572-c1cb77be5734" targetRef="sid-216515ff-91cb-4ec3-8d1e-c36a128f2dbf" name="保存成功">
        <conditionExpression xsi:type="tFormalExpression"><![CDATA[${save}]]></conditionExpression>
      </sequenceFlow>
      <sequenceFlow id="sid-1905e28e-c5ea-4827-913e-c3c4853056db" sourceRef="sid-8a8b73a7-b4ac-49f7-b572-c1cb77be5734" targetRef="sid-1600e3d8-61f9-428f-82c8-c048ef84c774" name="保存失败">
        <conditionExpression xsi:type="tFormalExpression"><![CDATA[${!save}]]></conditionExpression>
      </sequenceFlow>
    </subProcess>
    <!-- 错误边界事件 -->
    <boundaryEvent id="sid-ddef4f3c-3395-42e5-baa4-1122338da889" attachedToRef="sid-9405baaf-73a2-4f6d-8c17-3ce20b221bbe" cancelActivity="false" name="错误边界事件">
      <!-- 引用错误码 -->
      <errorEventDefinition errorRef="error1"/>
    </boundaryEvent>
    <sequenceFlow id="sid-792f09fd-d9f8-44a3-abe6-c01a42f5f1d8" sourceRef="sid-ddef4f3c-3395-42e5-baa4-1122338da889" targetRef="sid-9405baaf-73a2-4f6d-8c17-3ce20b221bbe"/>
    <!-- 服务任务 -->
    <serviceTask id="sid-8accfa7d-4feb-4d3d-8088-bd2df124b57a" activiti:exclusive="true" name="服务任务" activiti:delegateExpression="${myServiceTaskListener}"/>
    <!-- 结束事件1 -->
    <endEvent id="sid-2efe3807-4285-416c-a2b7-c3827ec433d2" name="结束事件1"/>
    <sequenceFlow id="sid-3747e8f1-b5c6-4b83-b8af-c74038303170" sourceRef="sid-8accfa7d-4feb-4d3d-8088-bd2df124b57a" targetRef="sid-2efe3807-4285-416c-a2b7-c3827ec433d2"/>
    <sequenceFlow id="sid-e12fb2e5-97ad-458a-9954-8531754b6bb1" sourceRef="sid-0347a044-9d2e-465b-a449-eb6699044ae4" targetRef="sid-9405baaf-73a2-4f6d-8c17-3ce20b221bbe"/>
    <sequenceFlow id="sid-1296aafe-77e0-46ed-be02-40e77e483512" sourceRef="sid-9405baaf-73a2-4f6d-8c17-3ce20b221bbe" targetRef="sid-8accfa7d-4feb-4d3d-8088-bd2df124b57a"/>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_error">
    <bpmndi:BPMNPlane bpmnElement="error-boundary-end" id="BPMNPlane_error">
      <bpmndi:BPMNShape id="shape-8d5f52a3-a6a2-4f64-9efb-e9837679722e" bpmnElement="sid-0347a044-9d2e-465b-a449-eb6699044ae4">
        <omgdc:Bounds x="-366.3918" y="140.0239" width="30.0" height="30.0"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="shape-486bc80b-61bf-464f-be0f-a586c65eb86e" bpmnElement="sid-9405baaf-73a2-4f6d-8c17-3ce20b221bbe">
        <omgdc:Bounds x="-289.65228" y="96.042305" width="321.05652" height="117.96317"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="shape-f95a940b-f150-49f8-9d86-09923329f6d0" bpmnElement="sid-1b0e1eec-d26b-4a7a-94b3-8e8b5970b3fa">
        <omgdc:Bounds x="-228.40327" y="117.33385" width="100.0" height="80.0"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="shape-07af35b3-f623-4fdd-99ae-675c6c7894e6" bpmnElement="sid-2efe3807-4285-416c-a2b7-c3827ec433d2">
        <omgdc:Bounds x="225.4221" y="139.25394" width="30.0" height="30.0"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="shape-bae0f412-1c38-4baf-a8d8-a4740dc0c63e" bpmnElement="sid-8accfa7d-4feb-4d3d-8088-bd2df124b57a">
        <omgdc:Bounds x="79.65822" y="114.25394" width="100.0" height="80.0"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge id="edge-b07f91be-b837-448d-a8a7-0892ac5b39a2" bpmnElement="sid-3747e8f1-b5c6-4b83-b8af-c74038303170">
        <omgdi:waypoint x="179.65819" y="154.25394"/>
        <omgdi:waypoint x="225.4221" y="154.25394"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNShape id="shape-f2b44140-d7d8-4110-8001-8eb61b3ae601" bpmnElement="sid-9f66c2ee-3281-486e-9aea-e27f29dad682">
        <omgdc:Bounds x="-280.5647" y="142.33385" width="30.0" height="30.0"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge id="edge-26b2554a-e5f0-4b44-a70a-00b3ff5812be" bpmnElement="sid-3ff4163b-067d-4e9b-8e26-ad05a1c9d7a2">
        <omgdi:waypoint x="-250.5647" y="157.33385"/>
        <omgdi:waypoint x="-228.40327" y="157.33385"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="edge-61a3490a-54fd-4ab1-a770-b76eb42652a1" bpmnElement="sid-e12fb2e5-97ad-458a-9954-8531754b6bb1">
        <omgdi:waypoint x="-336.3918" y="155.0239"/>
        <omgdi:waypoint x="-289.65228" y="155.02391"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="edge-5d002380-d175-4884-815c-14fc1759d1a4" bpmnElement="sid-1296aafe-77e0-46ed-be02-40e77e483512">
        <omgdi:waypoint x="31.404236" y="155.0239"/>
        <omgdi:waypoint x="79.65822" y="154.25394"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNShape id="shape-522ed462-bae8-444e-a8b9-477fda868b8c" bpmnElement="sid-ddef4f3c-3395-42e5-baa4-1122338da889">
        <omgdc:Bounds x="-116.11634" y="197.29118" width="30.0" height="30.0"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge id="edge-8a740a35-cad6-4347-8ef6-1a46a2ee8268" bpmnElement="sid-792f09fd-d9f8-44a3-abe6-c01a42f5f1d8">
        <omgdi:waypoint x="-101.11635" y="227.29118"/>
        <omgdi:waypoint x="-101.11634" y="265.13498"/>
        <omgdi:waypoint x="-209.38815" y="265.13498"/>
        <omgdi:waypoint x="-209.38815" y="214.0055"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNShape id="shape-df93b38f-f194-4162-a655-ec4ee7862752" bpmnElement="sid-1600e3d8-61f9-428f-82c8-c048ef84c774">
        <omgdc:Bounds x="-34.357986" y="176.21335" width="30.0" height="30.0"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge id="edge-6e2c6138-5753-4047-b044-9ce53ef91f30" bpmnElement="sid-bfbfcc21-b6db-4275-9726-0560d0c397dd">
        <omgdi:waypoint x="-128.40327" y="157.33385"/>
        <omgdi:waypoint x="-102.3249" y="157.33388"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNShape id="shape-ed1e9d9e-02f7-445b-be90-8e805e4b99e2" bpmnElement="sid-8a8b73a7-b4ac-49f7-b572-c1cb77be5734">
        <omgdc:Bounds x="-102.32489" y="137.33386" width="40.0" height="40.0"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="shape-92c333a1-02bf-4e06-a7a6-6efabb4c2c07" bpmnElement="sid-216515ff-91cb-4ec3-8d1e-c36a128f2dbf">
        <omgdc:Bounds x="-34.357986" y="107.18444" width="30.0" height="30.0"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge id="edge-e6ac924d-c7f7-428e-8f2c-189e005b8682" bpmnElement="sid-82b537d9-8377-4d7a-a3e1-7d204afe45dd">
        <omgdi:waypoint x="-82.32488" y="137.33385"/>
        <omgdi:waypoint x="-34.357986" y="122.18445"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="edge-efeec91d-d6e8-4106-baa0-f5c292ce0e78" bpmnElement="sid-1905e28e-c5ea-4827-913e-c3c4853056db">
        <omgdi:waypoint x="-82.32489" y="177.33386"/>
        <omgdi:waypoint x="-34.357983" y="191.21335"/>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>
自定义错误监听器
@Component
public class MyThrowErrorDelegateListener implements JavaDelegate, Serializable {

    private static final long serialVersionUID = 1L;

    @Override
    public void execute(DelegateExecution execution) {
        System.out.println("《================服务任务错误监听器================》");
        System.out.println("当前时间:" + DateUtil.format(new Date(), DatePattern.NORM_DATETIME_PATTERN));
        System.out.println("delegateTask.getProcessInstanceId() = " + execution.getProcessInstanceId());
        System.out.println("delegateTask.getProcessInstanceBusinessKey() = " + execution.getProcessInstanceBusinessKey());
        System.out.println("delegateTask.getEventName() = " + execution.getEventName());
        System.out.println("execution.getCurrentFlowElement().getName() = " + execution.getCurrentFlowElement().getName());
        // 抛出异常
        String errorCode = "123456";
        System.out.println("抛出错误码:" + errorCode);
        throw new BpmnError(errorCode);
    }
}
测试流程
@Test
public void deployAndStartProcessByErrorBoundaryAndEnd() {
    // 部署流程
    Deployment deploy = repositoryService.createDeployment()
            .addClasspathResource("processes/error-boundary-end.bpmn20.xml")
            .deploy();
    System.out.println("deploy = " + deploy);

    // 启动流程
    Map<String, Object> variables = new HashMap<>();
    variables.put("assignee", "user123456");
    String processDefinitionKey = "error-boundary-end";
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(processDefinitionKey, processDefinitionKey + ":1000011", variables);
    System.out.println("processInstance = " + processInstance);
}

@Test
public void completeTaskForErrorBoundaryAndEnd() {
    // 查询任务
    Task task = taskService.createTaskQuery().processInstanceId(PROCESS_INSTANCE_ID).taskAssignee("user123456").singleResult();
    System.out.println("task = " + task);
    // 完成任务
    Map<String, Object> hashMap = new HashMap<>();
    hashMap.put("save", true);
    taskService.complete(task.getId(), hashMap, true);
}
流程执行步骤
// 1.部署并启动流程
// 2.当前任务保存用户任务
// 3.完成用户任务save=false
// 4.触发错误结束事件,边界事件捕获到errorCode=123456,流程循环保存用户任务(如果一直是false)
// 5.当完成用户任务save=true
// 6.子流程结束
// 7.触发服务任务
// 8.结束流程

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1274637.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

基于Python Flask 的全流程全栈项目自己的实战心得

我基于Python Flask框架开发全流程全栈项目的实战经验和心得。我将介绍整个项目的架构设计、前后端交互、数据库管理以及部署等方面&#xff0c;并提供具体的代码示例。通过这个实例项目&#xff0c;你将学习到如何使用Flask构建一个完整的Web应用&#xff0c;并了解一些常见的…

关于PFMEA的风险评估都在这里——SunFMEA软件

1、评价严重度 严重度应该独立于发生度和探测度的评价&#xff0c;不能认为发生概率低或者探测能力强&#xff0c;失效就不会到达顾客手中&#xff0c;不会造成糟糕的失效影响&#xff0c;严重度就低。 其实&#xff0c;严重度评估的是已经识别的失效链的严重程度&#xff0c…

Cesium 加载倾斜摄影模型记录(osgb切片,shp拔高切片、模型加载、鼠标移入选中、点选查询功能)

一、shp模型拔高切片 shp如果数据量过大,做分类处理,加载会异常慢,所以需要先对其进行分割之后再进行切片(用qgis即可) 切片规则设置 1、记得勾选构造底面 2、如果你的shp数据中有高度字段的话,可以选择高度字段,如果没有的话,设置固定高度的高度比你的模型稍微高一点…

Vue语音播报,不用安装任何包和插件,直接调用。

Vue语音播报功能可以通过使用浏览器提供的Web Speech API来实现。这个API允许你的应用程序通过浏览器朗读文本&#xff0c;不用安装任何包和插件&#xff0c;直接调用。以下是一个简单的介绍&#xff0c;演示如何在Vue中使用语音提示功能&#xff1a; 一、JS版本 <template…

Java 多线程基础 线程4种创建方式

目录 什么是进程什么是多线程使用多线程的好处使用多线程的应用场景单线程与多线程之间的区别如何理解线程上下文切换使用多线程真的开启越多越好吗线程4种创建的方式1.继承Thread类2.使用Runnable3.使用Callable4.线程池的方式 多线程五种的状态如何优雅的停止一个线程 什么是…

实用篇 | Base64详解及代码示例

本文主要讲解了在http等协议传输过程中的base64编码~ 目录 1.什么是Base64&#xff1f; 2.什么是 Base64 编码&#xff1f; 3.编码规则 4.Base64 编码的作用 5.python中base64库 5.1.将一个mp3文件编码为Base64字符串 5.2.在Flask api设置时&#xff0c;以base64编码的…

TA-Lib学习研究笔记——Cycle Indicators (七)

TA-Lib学习研究笔记——Cycle Indicators &#xff08;七&#xff09; Cycle Indicators 周期指标函数组有HT_DCPERIOD, HT_DCPHASE, HT_PHASOR, HT_SINE, HT_TRENDMODE 。 1.HT_DCPERIOD Hilbert Transform - Dominant Cycle Period 函数名&#xff1a;HT_DCPERIOD 名称&am…

功能上新 | 搅拌车智能接料 防拉错 防溢出

据说99%的搅拌站都发生过这样的“糟心事”&#xff1a;驾驶员一恍惚进错了拌台、车还没停好位置就开始放料、放料一不小心就溢出、料没接完车先走了... 面对这样的事故&#xff0c;搅拌站通常的应对都是“下次要注意”。但我们都知道&#xff0c;是人都会犯错&#xff0c;这无…

简化客服系统运营的无代码集成方法,达钛科技助您实现客户运营和广告推广

无代码开发&#xff1a;简化电商与客服系统集成 在数字经济时代&#xff0c;电商平台和客服系统的高效集成对企业的成功至关重要。传统的系统集成往往依赖复杂的API开发&#xff0c;既耗时又费力。达钛科技致力于通过无代码开发的方式&#xff0c;提供简单直观的解决方案&…

Kettle 浅入浅出

前言 最近又要迭代客户定制化的数据处理系统了。提到数据处理&#xff0c;不禁想到了以前使用过的 ETL 处理工具 Kettle。本文将对 Kettle 做一些简单的介绍。 Kettle 介绍 在介绍 Kettle 前先了解下什么是 ETL&#xff0c;ETL 是 Extract-Transform-Load 的缩写&#xff0c…

【opencv】计算机视觉基础知识

目录 前言 1、什么是计算机视觉 2、图片处理基础操作 2.1 图片处理&#xff1a;读入图像 2.2 图片处理&#xff1a;显示图像 2.3 图片处理&#xff1a;图像保存 3、图像处理入门基础 3.1 图像成像原理介绍 3.2 图像分类 3.2.1 二值图像 3.2.2灰度图像 3.2.3彩色图像…

A++ 敏捷开发-1 如何改善

1 如何改善 敏捷开发过程改进案例 5月 A公司一直专门为某电信公司提供针对客服、线上播放等服务服务。 张工是公司的中层管理者&#xff0c;管理好几个开发团队&#xff0c;有5位项目经理向他汇报。 他听说老同学的团队都开始用敏捷开发&#xff0c;很感兴趣&#xff0c;便参…

【Linux】I/O多路转接技术

I/O多路转接技术 一、I/O多路转接之select1、select函数2、fd_set的相关内容3、如何在代码中高效的使用select函数4、select服务器5、select的优缺点6、select的适用场景 二、I/O多路转接之poll1、poll函数2、struct pollfd结构2、poll服务器3、poll的优缺点 三、I/O多路转接之…

一个简单的参数帮助框架,c实现

文章目录 具体实现如下&#xff1a; #include <stdio.h> #include <stdlib.h> #include <string.h> void print_help(char *argv[]) { printf("Usage: %s [options]\n", argv[0]); printf("Options:\n"); printf(" -h, -…

使用SLS日志服务采集Kong网关的日志

一、阿里云SLS 官方的接入文档已比较丰富了&#xff0c;本文不意重复说明此事。 站在使用的角度&#xff0c;以采集Kong的日志为示例&#xff0c;说明我们应该如何治理日志。 说白了&#xff0c;本文是想给你怎么省钱作一个建议&#xff0c;希望不会让你公司也“降本增笑”。…

1-cuda与gpu编程

文章目录 CUDA与GPU编程1. 并行处理与GPU体系架构1.1 并行处理简介1.1.1 串行处理与并行处理的区别1.1.2 并行处理的概念1.1.3 常见的并行处理 1.2 GPU并行处 理1.2.1 GPU与CPU并行处理的异同1.2.2 CPU的优化方式1.2.3 GPU的特点 1.3 环境搭建1.4 环境变量配置 参考环境搭建设置…

用HeidiSQL在MySQL中创建新的数据库

用有权限的用户登录&#xff1a; 右键单击&#xff0c;选择&#xff1a; 输入要创建的数据库名称&#xff0c;然后点击“确定”&#xff1a; 刷新下&#xff0c;就看到新创建的数据库了&#xff1a; 在新创建的数据库中&#xff0c;就可以做其它操作了&#xff0c;例如…

三、使用CRT连接三台虚拟机

目录 1、建立连接 2、参数配置 3、设置主题,颜色和仿真 1、建立连接

厉害了!!FastReport 全系.NET控件升级v2024,已覆盖支持全新.NET 8 框架 ~

FastReport 作为一款国际知名的报表开发控件&#xff0c;其跨平台的多语言脚本引擎FastScript&#xff0c;桌面OLAP FastCube&#xff0c;被世界各地的开发者所认可。 此次FastReport旗下.NET全系更新至v2024新版&#xff0c;在此版本中&#xff0c;上线了许多开发者关注的功能…

SpringSecurity的默认登录页的使用

SpringSecurity的默认登录页的使用 01 前期准备 引入依赖 <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><!--mysql驱动--><dependency><grou…