中间事件 Intermediate Events) 在开始事件和结束时间之间的时间都是中间事件,中间事件会影响流程的流转路线。这类事件即可以捕获触发器又可以抛出结果。 [图片] 图片来自AWS(https://docs.awspaas.com) 分为两类事件 捕获事件。当流程执行到该事件后,它会中断执行,等待触发器。当 ..

Intermediate Events of Activiti 6.x Events

本贴最后更新于 191 天前,其中的信息可能已经时异事殊

中间事件 Intermediate Events)

开始事件结束时间之间的时间都是中间事件,中间事件会影响流程的流转路线。这类事件即可以捕获触发器又可以抛出结果。
转载自 AWS

图片来自AWS(https://docs.awspaas.com)

分为两类事件

捕获时间事件

当流程执行到到此时,会产生中断,流程引擎会创建一个定时器,当定时器触发后事件结束,继续执行下一步流程。
流程图:
image.png
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">
  <process id="catch_timer_process_1" name="中间捕获时间事件" isExecutable="true">
    <startEvent id="startEvent1">
      <extensionElements>
        <activiti:executionListener event="start" class="com.lei2j.activiti.executionListener.ExecuteListenerOne"></activiti:executionListener>
      </extensionElements>
    </startEvent>
    <intermediateCatchEvent id="sid-5877CE1B-3DD4-4584-8439-5C64607E987F">
      <extensionElements>
        <activiti:executionListener event="start" expression="${executionListenerImpl.start(execution)}"></activiti:executionListener>
        <activiti:executionListener event="end" expression="${executionListenerImpl.end(execution.eventName)}"></activiti:executionListener>
      </extensionElements>
      <timerEventDefinition>
        <timeDuration>R2/PT30S</timeDuration>
      </timerEventDefinition>
    </intermediateCatchEvent>
    <sequenceFlow id="sid-A3BF7640-1129-4D7A-BDA1-4E2BC41674E1" sourceRef="startEvent1" targetRef="sid-5877CE1B-3DD4-4584-8439-5C64607E987F"></sequenceFlow>
    <endEvent id="sid-FB26EFC4-F557-49C4-9AA3-BA7FDB37086A">
      <extensionElements>
        <activiti:executionListener event="start" expression="${executionListenerImpl.instanceEnd(execution)}"></activiti:executionListener>
      </extensionElements>
    </endEvent>
    <sequenceFlow id="sid-5A92CF2D-EE60-4111-8815-4A7723BEA1BB" sourceRef="sid-5877CE1B-3DD4-4584-8439-5C64607E987F" targetRef="sid-FB26EFC4-F557-49C4-9AA3-BA7FDB37086A"></sequenceFlow>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_catch_timer_process_1">
    <bpmndi:BPMNPlane bpmnElement="catch_timer_process_1" id="BPMNPlane_catch_timer_process_1">
      <bpmndi:BPMNShape bpmnElement="startEvent1" id="BPMNShape_startEvent1">
        <omgdc:Bounds height="30.0" width="30.0" x="90.0" y="163.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-5877CE1B-3DD4-4584-8439-5C64607E987F" id="BPMNShape_sid-5877CE1B-3DD4-4584-8439-5C64607E987F">
        <omgdc:Bounds height="31.0" width="31.0" x="175.0" y="162.5"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-FB26EFC4-F557-49C4-9AA3-BA7FDB37086A" id="BPMNShape_sid-FB26EFC4-F557-49C4-9AA3-BA7FDB37086A">
        <omgdc:Bounds height="28.0" width="28.0" x="251.0" y="164.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="sid-A3BF7640-1129-4D7A-BDA1-4E2BC41674E1" id="BPMNEdge_sid-A3BF7640-1129-4D7A-BDA1-4E2BC41674E1">
        <omgdi:waypoint x="119.99974649101308" y="178.08720782843614"></omgdi:waypoint>
        <omgdi:waypoint x="175.00027040958605" y="178.4069783163348"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-5A92CF2D-EE60-4111-8815-4A7723BEA1BB" id="BPMNEdge_sid-5A92CF2D-EE60-4111-8815-4A7723BEA1BB">
        <omgdi:waypoint x="206.99963478241017" y="178.39189435957832"></omgdi:waypoint>
        <omgdi:waypoint x="251.00031956539112" y="178.09459243536898"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>

流程执行到中间捕获事件时产生中断,引擎生成一个定时器,在定时器被触发后,捕获事件完成,继续执行流程下一步。

捕获信号事件

当执行到中断信号事件,将等待该信号被触发后,流程继续下一步。

流程图:
image.png

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">

  <signal id="catchSignalTest1" name="catchSignal_1"></signal>
  <process id="catchSignalProcess_1" name="捕获信号事件" isExecutable="true">
    <startEvent id="startEvent1"></startEvent>
    <intermediateCatchEvent id="sid-A9637C1F-3B8D-4D72-BEFF-A81DC68693A0">
      <signalEventDefinition signalRef="catchSignalTest1"></signalEventDefinition>
    </intermediateCatchEvent>
    <sequenceFlow id="sid-C8276B13-B838-44A8-AB32-6D81B1858795" sourceRef="startEvent1" targetRef="sid-A9637C1F-3B8D-4D72-BEFF-A81DC68693A0"></sequenceFlow>
    <endEvent id="sid-2907459A-B353-481A-A4B2-C5D1587B1912">
      <extensionElements>
        <activiti:executionListener event="start"
                                    class="com.lei2j.activiti.executionListener.CatchSignalEventExecutionListener"/>
      </extensionElements>
    </endEvent>
    <sequenceFlow id="sid-DF4FB6C0-809A-4337-949E-3BE362FA1D14" sourceRef="sid-A9637C1F-3B8D-4D72-BEFF-A81DC68693A0" targetRef="sid-2907459A-B353-481A-A4B2-C5D1587B1912"></sequenceFlow>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_catchSignalProcess_1">
    <bpmndi:BPMNPlane bpmnElement="catchSignalProcess_1" id="BPMNPlane_catchSignalProcess_1">
      <bpmndi:BPMNShape bpmnElement="startEvent1" id="BPMNShape_startEvent1">
        <omgdc:Bounds height="30.0" width="30.0" x="90.0" y="180.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-A9637C1F-3B8D-4D72-BEFF-A81DC68693A0" id="BPMNShape_sid-A9637C1F-3B8D-4D72-BEFF-A81DC68693A0">
        <omgdc:Bounds height="30.0" width="30.0" x="180.0" y="180.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-2907459A-B353-481A-A4B2-C5D1587B1912" id="BPMNShape_sid-2907459A-B353-481A-A4B2-C5D1587B1912">
        <omgdc:Bounds height="28.0" width="28.0" x="255.0" y="181.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="sid-DF4FB6C0-809A-4337-949E-3BE362FA1D14" id="BPMNEdge_sid-DF4FB6C0-809A-4337-949E-3BE362FA1D14">
        <omgdi:waypoint x="210.0" y="195.0"></omgdi:waypoint>
        <omgdi:waypoint x="255.0" y="195.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-C8276B13-B838-44A8-AB32-6D81B1858795" id="BPMNEdge_sid-C8276B13-B838-44A8-AB32-6D81B1858795">
        <omgdi:waypoint x="120.0" y="195.0"></omgdi:waypoint>
        <omgdi:waypoint x="180.0" y="195.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>

可以定义抛出信号事件(Signal Intermediate Throwing Event)或者使用 API(runtimeService.signalEventReceived)来完成信号事件,使其流程进入下一步。

捕获消息事件

当流程执行到此处时,执行中断,等待抛出消息事件或 API 发出消息后,继续流程下一步。

流程图:
image.png
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">
  <message id="CatchMessage_1" name="CatchMessage_1"></message>
  <process id="CatchMessageProcess_1" name="捕获消息事件Test" isExecutable="true">
    <startEvent id="startEvent1"></startEvent>
    <intermediateCatchEvent id="sid-8CC37C58-B64C-4BA5-8CE2-D4C7554D24A5">
      <messageEventDefinition messageRef="CatchMessage_1"></messageEventDefinition>
    </intermediateCatchEvent>
    <endEvent id="sid-22741D71-C41D-429C-A1BD-E92F740E216F">
      <extensionElements>
        <activiti:executionListener event="end" class="com.lei2j.activiti.executionListener.CatchMessageExecutionListener"></activiti:executionListener>
      </extensionElements>
    </endEvent>
    <sequenceFlow id="sid-DB2A802F-9DCF-4752-A2D9-2F9075952F62" sourceRef="sid-8CC37C58-B64C-4BA5-8CE2-D4C7554D24A5" targetRef="sid-22741D71-C41D-429C-A1BD-E92F740E216F"></sequenceFlow>
    <sequenceFlow id="sid-2EED92D5-9877-4484-8F77-F00E09B748F2" sourceRef="startEvent1" targetRef="sid-8CC37C58-B64C-4BA5-8CE2-D4C7554D24A5"></sequenceFlow>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_CatchMessageProcess_1">
    <bpmndi:BPMNPlane bpmnElement="CatchMessageProcess_1" id="BPMNPlane_CatchMessageProcess_1">
      <bpmndi:BPMNShape bpmnElement="startEvent1" id="BPMNShape_startEvent1">
        <omgdc:Bounds height="30.0" width="30.0" x="100.0" y="163.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-8CC37C58-B64C-4BA5-8CE2-D4C7554D24A5" id="BPMNShape_sid-8CC37C58-B64C-4BA5-8CE2-D4C7554D24A5">
        <omgdc:Bounds height="30.0" width="30.0" x="195.0" y="163.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-22741D71-C41D-429C-A1BD-E92F740E216F" id="BPMNShape_sid-22741D71-C41D-429C-A1BD-E92F740E216F">
        <omgdc:Bounds height="28.0" width="28.0" x="270.0" y="164.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="sid-DB2A802F-9DCF-4752-A2D9-2F9075952F62" id="BPMNEdge_sid-DB2A802F-9DCF-4752-A2D9-2F9075952F62">
        <omgdi:waypoint x="225.0" y="178.0"></omgdi:waypoint>
        <omgdi:waypoint x="270.0" y="178.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-2EED92D5-9877-4484-8F77-F00E09B748F2" id="BPMNEdge_sid-2EED92D5-9877-4484-8F77-F00E09B748F2">
        <omgdi:waypoint x="130.0" y="178.0"></omgdi:waypoint>
        <omgdi:waypoint x="195.0" y="178.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>

可以定义抛出消息事件或使用 API(runtimeService.createExecutionQuery().messageEventSubscriptionName();runtimeService.messageEventReceived)完成消息事件,继续流程的下一步。

抛出信号事件

当流程实例执行抛出信号事件时,流程引擎发出一个信号,信号发出后事件结束,流程实例继续向下一步执行。

流程图:
image.png

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">
  <signal id="SignalTest1" name="SignalTest1" activiti:scope="global"></signal>
  <process id="ThrowSignalProcess_1" name="抛出信号事件" isExecutable="true">
    <startEvent id="startEvent1"></startEvent>
    <intermediateThrowEvent id="sid-CAAB3F0D-B4FC-42B0-8338-3C39F31C0D9F">
      <signalEventDefinition signalRef="SignalTest1"></signalEventDefinition>
    </intermediateThrowEvent>
    <sequenceFlow id="sid-6386BB39-6AA0-4973-825C-FABFDE2E3652" sourceRef="startEvent1" targetRef="sid-CAAB3F0D-B4FC-42B0-8338-3C39F31C0D9F"></sequenceFlow>
    <endEvent id="sid-78212B94-B2A2-4963-92EC-BA2B08058E12">
      <extensionElements>
        <activiti:executionListener event="end" class="com.lei2j.activiti.executionListener.ThrowSignalExecutionListener"></activiti:executionListener>
      </extensionElements>
    </endEvent>
    <sequenceFlow id="sid-04E5A365-5168-40B4-999A-46B56EB597E1" sourceRef="sid-CAAB3F0D-B4FC-42B0-8338-3C39F31C0D9F" targetRef="sid-78212B94-B2A2-4963-92EC-BA2B08058E12"></sequenceFlow>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_ThrowSignalProcess_1">
    <bpmndi:BPMNPlane bpmnElement="ThrowSignalProcess_1" id="BPMNPlane_ThrowSignalProcess_1">
      <bpmndi:BPMNShape bpmnElement="startEvent1" id="BPMNShape_startEvent1">
        <omgdc:Bounds height="30.0" width="30.0" x="-15.0" y="-15.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-CAAB3F0D-B4FC-42B0-8338-3C39F31C0D9F" id="BPMNShape_sid-CAAB3F0D-B4FC-42B0-8338-3C39F31C0D9F">
        <omgdc:Bounds height="30.0" width="30.0" x="-15.0" y="-15.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-78212B94-B2A2-4963-92EC-BA2B08058E12" id="BPMNShape_sid-78212B94-B2A2-4963-92EC-BA2B08058E12">
        <omgdc:Bounds height="28.0" width="28.0" x="-14.0" y="-14.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="sid-6386BB39-6AA0-4973-825C-FABFDE2E3652" id="BPMNEdge_sid-6386BB39-6AA0-4973-825C-FABFDE2E3652">
        <omgdi:waypoint x="130.0" y="178.0"></omgdi:waypoint>
        <omgdi:waypoint x="270.0" y="178.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-04E5A365-5168-40B4-999A-46B56EB597E1" id="BPMNEdge_sid-04E5A365-5168-40B4-999A-46B56EB597E1">
        <omgdi:waypoint x="299.9999790271242" y="178.02508357696843"></omgdi:waypoint>
        <omgdi:waypoint x="420.5000195746841" y="178.22658866149612"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>

抛出信号后,所有订阅该信号的的信号事件都会被触发。抛出后,继续流程的下一步。

抛出补偿中间事件

当执行到抛出补偿事件时触发该流程已完成的任务的边界补偿事件(Compensate Boundary Interrputing Event),完成补偿操作后自动执行下一步操作。

  1. 一般补偿事件案例

流程图:
ThrowCompensateEventProcess_1.png

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/test">
  <process id="throwCompensationProcess_1" name="throwCompensationProcess_1" isExecutable="true">
    <startEvent id="startevent1" name="Start"></startEvent>
    <serviceTask id="servicetask1" name="自动处理" activiti:expression="#{resumeService.throwCompensationProcess1(execution)}">
      <multiInstanceLoopCharacteristics isSequential="true">
        <loopCardinality>3</loopCardinality>
      </multiInstanceLoopCharacteristics>
    </serviceTask>
    <intermediateThrowEvent id="compensationintermediatethrowevent1" name="CompensationThrowingEvent">
      <compensateEventDefinition waitForCompletion="true"></compensateEventDefinition>
    </intermediateThrowEvent>
    <endEvent id="endevent1" name="End"></endEvent>
    <sequenceFlow id="flow1" sourceRef="compensationintermediatethrowevent1" targetRef="endevent1"></sequenceFlow>
    <sequenceFlow id="flow2" sourceRef="servicetask1" targetRef="compensationintermediatethrowevent1"></sequenceFlow>
    <sequenceFlow id="flow3" sourceRef="startevent1" targetRef="servicetask1"></sequenceFlow>
    <serviceTask id="servicetask2" name="补偿程序"
                 activiti:expression="#{resumeService.throwCompensationProcess2(execution)}" isForCompensation="true"></serviceTask>
    <endEvent id="endevent2" name="End"></endEvent>
    <sequenceFlow id="flow4" sourceRef="servicetask2" targetRef="endevent2"></sequenceFlow>
    <boundaryEvent id="boundarycompensation1" name="Compensate" attachedToRef="servicetask1" cancelActivity="true">
      <compensateEventDefinition waitForCompletion="true"/>
    </boundaryEvent>
    <association id="association1" sourceRef="boundarycompensation1" targetRef="servicetask2" associationDirection="None"></association>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_throwCompensationProcess_1">
    <bpmndi:BPMNPlane bpmnElement="throwCompensationProcess_1" id="BPMNPlane_throwCompensationProcess_1">
      <bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
        <omgdc:Bounds height="30.0" width="30.0" x="190.0" y="210.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="servicetask1" id="BPMNShape_servicetask1">
        <omgdc:Bounds height="55.0" width="105.0" x="285.0" y="200.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="compensationintermediatethrowevent1" id="BPMNShape_compensationintermediatethrowevent1">
        <omgdc:Bounds height="30.0" width="30.0" x="450.0" y="210.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
        <omgdc:Bounds height="28.0" width="28.0" x="530.0" y="210.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="servicetask2" id="BPMNShape_servicetask2">
        <omgdc:Bounds height="55.0" width="105.0" x="290.0" y="333.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="endevent2" id="BPMNShape_endevent2">
        <omgdc:Bounds height="28.0" width="28.0" x="325.0" y="440.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="association1" id="BPMNShape_association1">
        <omgdc:Bounds height="62.29863621192561" width="8.327832078669417" x="334.1721679213306" y="270.7013637880744"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="boundarycompensation1" id="BPMNShape_boundarycompensation1">
        <omgdc:Bounds height="30.0" width="30.0" x="317.08728677218915" y="240.10483746183536"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="association1" id="BPMNEdge_association1">
        <omgdi:waypoint x="334.07474805609303" y="269.972587716833"></omgdi:waypoint>
        <omgdi:waypoint x="342.5" y="333.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
        <omgdi:waypoint x="479.9987984139044" y="224.81014179222905"></omgdi:waypoint>
        <omgdi:waypoint x="530.0011214803559" y="224.17720099391957"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
        <omgdi:waypoint x="390.0" y="226.47058823529412"></omgdi:waypoint>
        <omgdi:waypoint x="450.0028826751491" y="225.2940611240167"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3">
        <omgdi:waypoint x="219.99733072335283" y="225.2829685042142"></omgdi:waypoint>
        <omgdi:waypoint x="285.0" y="226.50943396226415"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow4" id="BPMNEdge_flow4">
        <omgdi:waypoint x="341.47058823529414" y="388.0"></omgdi:waypoint>
        <omgdi:waypoint x="339.52369738641573" y="440.00979839146476"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>

自动处理任务有一个边界补偿事件,在自动处理任务完成后,流程到达抛出补偿事件,触发边界补偿事件(只有当自动处理这个任务完成才会触发边界补偿操作。如果补偿处理在子流程中,则子流程必须完成,才会进行补偿操作。),完成补偿事件(补偿程序)后继续执行下一步。上面例子,展示了在自动处理任务执行了 3 次后,补偿操作也会执行 3 次。

2.多补偿事件执行顺序

流程图:
ThrowMultiCompensateEventProcess_2.png

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/test">
  <process id="throwMultiCompensationProcess_2" name="多补偿事件处理顺序" isExecutable="true">
    <startEvent id="startevent1" name="Start"></startEvent>
    <serviceTask id="servicetask1" name="First task" activiti:expression="#{resumeService.throwMultiCompensationProcess1(execution)}"></serviceTask>
    <serviceTask id="servicetask2" name="Second task" activiti:expression="#{resumeService.throwMultiCompensationProcess2(execution)}"></serviceTask>
    <intermediateThrowEvent id="compensationintermediatethrowevent1" name="CompensationThrowingEvent">
      <compensateEventDefinition waitForCompletion="true"></compensateEventDefinition>
    </intermediateThrowEvent>
    <endEvent id="endevent2" name="End"></endEvent>
    <sequenceFlow id="flow2" sourceRef="compensationintermediatethrowevent1" targetRef="endevent2"></sequenceFlow>
    <sequenceFlow id="flow3" sourceRef="servicetask1" targetRef="servicetask2"></sequenceFlow>
    <sequenceFlow id="flow4" sourceRef="servicetask2" targetRef="compensationintermediatethrowevent1"></sequenceFlow>
    <boundaryEvent id="boundarycompensation1" name="Compensate" attachedToRef="servicetask2" cancelActivity="true">
      <compensateEventDefinition waitForCompletion="true"></compensateEventDefinition>
    </boundaryEvent>
    <boundaryEvent id="boundarycompensation2" name="Compensate" attachedToRef="servicetask1" cancelActivity="true">
      <compensateEventDefinition waitForCompletion="true"></compensateEventDefinition>
    </boundaryEvent>
    <serviceTask id="servicetask3" name="补偿-1"
                 activiti:expression="#{resumeService.throwMultiCompensationProcess3(execution)}" isForCompensation="true"></serviceTask>
    <serviceTask id="servicetask4" name="补偿-2"
                 activiti:expression="#{resumeService.throwMulitCompensationProcess4(execution)}" isForCompensation="true"></serviceTask>
    <endEvent id="endevent3" name="End"></endEvent>
    <sequenceFlow id="flow5" sourceRef="servicetask3" targetRef="endevent3"></sequenceFlow>
    <endEvent id="endevent4" name="End"></endEvent>
    <sequenceFlow id="flow6" sourceRef="servicetask4" targetRef="endevent4"></sequenceFlow>
    <sequenceFlow id="flow7" sourceRef="startevent1" targetRef="servicetask1"></sequenceFlow>
    <association id="association1" sourceRef="boundarycompensation2" targetRef="servicetask3" associationDirection="None"></association>
    <association id="association2" sourceRef="boundarycompensation1" targetRef="servicetask4" associationDirection="None"></association>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_myProcess">
    <bpmndi:BPMNPlane bpmnElement="throwMultiCompensationProcess_2" id="BPMNPlane_myProcess">
      <bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
        <omgdc:Bounds height="30.0" width="30.0" x="160.0" y="190.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="servicetask1" id="BPMNShape_servicetask1">
        <omgdc:Bounds height="55.0" width="105.0" x="240.0" y="180.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="servicetask2" id="BPMNShape_servicetask2">
        <omgdc:Bounds height="55.0" width="105.0" x="410.0" y="180.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="compensationintermediatethrowevent1" id="BPMNShape_compensationintermediatethrowevent1">
        <omgdc:Bounds height="30.0" width="30.0" x="570.0" y="190.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="endevent2" id="BPMNShape_endevent2">
        <omgdc:Bounds height="28.0" width="28.0" x="650.0" y="190.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="boundarycompensation1" id="BPMNShape_boundarycompensation1">
        <omgdc:Bounds height="30.0" width="30.0" x="499.83878593290046" y="220.3397797515428"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="boundarycompensation2" id="BPMNShape_boundarycompensation2">
        <omgdc:Bounds height="30.0" width="30.0" x="316.63196696119695" y="220.45140497228354"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="servicetask3" id="BPMNShape_servicetask3">
        <omgdc:Bounds height="55.0" width="105.0" x="260.0" y="330.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="servicetask4" id="BPMNShape_servicetask4">
        <omgdc:Bounds height="55.0" width="105.0" x="448.0" y="330.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="endevent3" id="BPMNShape_endevent3">
        <omgdc:Bounds height="28.0" width="28.0" x="295.0" y="430.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="endevent4" id="BPMNShape_endevent4">
        <omgdc:Bounds height="28.0" width="28.0" x="483.0" y="430.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="association1" id="BPMNShape_association1">
        <omgdc:Bounds height="79.53390284281593" width="16.09373466668376" x="312.5" y="250.46609715718407"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="association2" id="BPMNShape_association2">
        <omgdc:Bounds height="78.88083965083888" width="11.948582741431665" x="500.5" y="251.11916034916112"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="association1" id="BPMNEdge_association1">
        <omgdi:waypoint x="328.657002730539" y="250.15343162939124"></omgdi:waypoint>
        <omgdi:waypoint x="312.5" y="330.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="association2" id="BPMNEdge_association2">
        <omgdi:waypoint x="512.5922675911023" y="250.1705975084962"></omgdi:waypoint>
        <omgdi:waypoint x="500.5" y="330.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
        <omgdi:waypoint x="599.9987984139044" y="204.81014179222905"></omgdi:waypoint>
        <omgdi:waypoint x="650.0011214803559" y="204.17720099391957"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3">
        <omgdi:waypoint x="345.0" y="207.5"></omgdi:waypoint>
        <omgdi:waypoint x="410.0" y="207.5"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow4" id="BPMNEdge_flow4">
        <omgdi:waypoint x="515.0" y="206.42857142857142"></omgdi:waypoint>
        <omgdi:waypoint x="570.0031227230484" y="205.3060587199378"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow5" id="BPMNEdge_flow5">
        <omgdi:waypoint x="311.3872832369942" y="385.0"></omgdi:waypoint>
        <omgdi:waypoint x="309.566010839176" y="430.01144640322184"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow6" id="BPMNEdge_flow6">
        <omgdi:waypoint x="499.3872832369942" y="385.0"></omgdi:waypoint>
        <omgdi:waypoint x="497.566010839176" y="430.01144640322184"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow7" id="BPMNEdge_flow7">
        <omgdi:waypoint x="189.99660595085598" y="205.31907672235863"></omgdi:waypoint>
        <omgdi:waypoint x="240.0" y="206.38297872340425"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>

当流程抛出补偿事件时,多个边界补偿事件会按照倒序依次完成补偿事件。也就是说,最先完成的流程任务,其补偿处理者最后执行。对于并行的任务流程,先完成的任务,其补偿处理者后执行。

回帖
请输入回帖内容...