目录
- 定义
- 图形标记
- XML内容
- 使用示例
- 视频教程
定义
取消结束事件只能与 BPMN 事务子流程结合使用,它可以取消一个事务子流程的执行,同时
也只能在子流程中执行。实际应用中,会把取消事件,事务子流程,补偿事件一起用。当到达取消
结束事件时,会抛出取消事件,它必须被取消边界事件捕获。取消边界事件会取消事务,并触发补
偿机制。
图形标记
取消结束事件显示为标准的结束事件(粗边圆圈),包含一个取消图标。取消图标是全黑的,
表示触发语法,如图所示:
XML内容
取消结束事件内容是一个结束事件,包含 cancelEventDefinition 子元素:
<process id="cancelEndEventProcess">
<endEvent id="cancelEndEvent">
<cancelEventDefinition/>
</endEvent>
</process>
使用示例
取消结束事件,只能与事务子流程(Transaction Subprocess)一起使用。当到达取消结束事件
时,会抛出取消事件,且必须由取消边界事件(Cancel Boundary Event)捕获。之后这个取消边界
事件将取消事务,并触发补偿(compensation)。
下面我们看一个使用取消结束事件的示例流程,如图所示是一个系统上线流程,流程启
动后进入系统上线事务子流程,首先到达“人工上线”用户任务节点,办理完成后到达取消结束事
件,抛出取消事件,触发“自动回滚”补偿,并触发取消边界事件以及结束子流程进而流转到“用
户排查”用户任务节点。这个示例流程中涉及到用户任务节点、服务任务节点、事务子流程和取消
边界事件,这些都是 BPMN 定义的流程元素,在后面的章节中会展开介绍。
<error id="errorFlag" errorCode="500" />
<process id="ThransactionSubProcessTest" name="子流程-事务子流程" isExecutable="true">
<startEvent id="a1bc9933739624c6694151aff2dce872b" />
<userTask id="aa49686c18f1c48879976ba75a55fcbc6" name="用户提交订单">
<extensionElements>
<flowable:formData />
<flowable:assigneeType>static</flowable:assigneeType>
</extensionElements>
</userTask>
<sequenceFlow id="ab3c3111802e74e1c829879ce06ef62f1" sourceRef="a1bc9933739624c6694151aff2dce872b" targetRef="aa49686c18f1c48879976ba75a55fcbc6" />
<transaction id="Activity_1vnyjkd" name="事务子流程">
<startEvent id="Event_12nf6w8">
<extensionElements>
<flowable:formData />
</extensionElements>
</startEvent>
<sequenceFlow id="Flow_1qdwcnq" sourceRef="Event_12nf6w8" targetRef="Gateway_1swfvxl" />
<parallelGateway id="Gateway_1swfvxl" />
<sequenceFlow id="Flow_17rtq7v" sourceRef="Gateway_1swfvxl" targetRef="Activity_1gw2yen" />
<serviceTask id="Activity_1gw2yen" name="锁定库存" flowable:class="com.dragon.test.bpmn.delegate.TreasuryLockService">
<extensionElements>
<flowable:formData />
<flowable:assigneeType>static</flowable:assigneeType>
</extensionElements>
</serviceTask>
<userTask id="Activity_0s32nn4" name="用户取消订单">
<extensionElements>
<flowable:formData />
<flowable:assigneeType>static</flowable:assigneeType>
</extensionElements>
</userTask>
<sequenceFlow id="Flow_0x4x7li" sourceRef="Gateway_1swfvxl" targetRef="Activity_0s32nn4" />
<userTask id="Activity_0k0ojol" name="用户支付订单">
<extensionElements>
<flowable:formData />
<flowable:assigneeType>static</flowable:assigneeType>
</extensionElements>
</userTask>
<sequenceFlow id="Flow_107046y" sourceRef="Activity_1gw2yen" targetRef="Activity_0k0ojol" />
<sequenceFlow id="Flow_1yuazgn" sourceRef="Activity_0k0ojol" targetRef="Activity_0bi67sc" />
<serviceTask id="Activity_0bi67sc" name="扣减库存" flowable:class="com.dragon.test.bpmn.delegate.TreasuryDeductService">
<extensionElements>
<flowable:assigneeType>static</flowable:assigneeType>
<flowable:formData />
</extensionElements>
</serviceTask>
<endEvent id="Event_167temk" />
<sequenceFlow id="Flow_0pkp6lj" sourceRef="Activity_0bi67sc" targetRef="Event_167temk" />
<endEvent id="Event_1mt0jp2">
<cancelEventDefinition />
</endEvent>
<boundaryEvent id="Event_1w62z13" attachedToRef="Activity_0bi67sc">
<errorEventDefinition errorRef="errorFlag" flowable:errorVariableLocalScope="false" flowable:errorVariableTransient="false" />
</boundaryEvent>
<boundaryEvent id="Event_0fblty6" name="30分钟" attachedToRef="Activity_0k0ojol">
<timerEventDefinition>
<timeDuration>PT3M</timeDuration>
</timerEventDefinition>
</boundaryEvent>
<boundaryEvent id="Event_0dzq6vl" attachedToRef="Activity_1gw2yen">
<compensateEventDefinition />
</boundaryEvent>
<serviceTask id="Activity_15oy2bt" name="释放库存" isForCompensation="true" flowable:class="com.dragon.test.bpmn.delegate.TreasuryReleaseService" />
<boundaryEvent id="Event_0rv7u1v" attachedToRef="Activity_0k0ojol">
<compensateEventDefinition />
</boundaryEvent>
<serviceTask id="Activity_0gw5xlk" name="费用退回" isForCompensation="true" flowable:class="com.dragon.test.bpmn.delegate.RefundPaymentService" />
<association id="Association_1a1b669" associationDirection="One" sourceRef="Event_0dzq6vl" targetRef="Activity_15oy2bt" />
<association id="Association_0vig570" associationDirection="One" sourceRef="Event_0rv7u1v" targetRef="Activity_0gw5xlk" />
</transaction>
<sequenceFlow id="Flow_0ynhbof" sourceRef="aa49686c18f1c48879976ba75a55fcbc6" targetRef="Activity_1vnyjkd" />
<boundaryEvent id="Event_0lxd35r" attachedToRef="Activity_1vnyjkd">
<cancelEventDefinition />
</boundaryEvent>
<sequenceFlow id="Flow_0p83e5j" sourceRef="Event_0lxd35r" targetRef="Activity_0xmvtli" />
<serviceTask id="Activity_0xmvtli" name="自动取消订单" flowable:class="com.dragon.test.bpmn.delegate.CancelOrderService">
<extensionElements>
<flowable:formData />
<flowable:assigneeType>static</flowable:assigneeType>
</extensionElements>
</serviceTask>
<endEvent id="Event_0h8me6c" />
<sequenceFlow id="Flow_1vvt0is" sourceRef="Activity_0xmvtli" targetRef="Event_0h8me6c" />
<endEvent id="Event_1954lc4" />
<sequenceFlow id="Flow_0kcxljy" sourceRef="Activity_1vnyjkd" targetRef="Event_1954lc4" />
</process>
::: warning 注意
⑴取消结束事件只能使用在事务子流程中
⑵取消结束事件会触发依附在子流程上的取消边界事件(取消结束事件会被抛出,而取消边界
事件则会捕获事件)
⑶在 BPMN2.0 中对于已经完成的活动,可以使用补偿机制,而对于一些正在进行的活动,不
能使用补偿机制,而使用取消机制。取消事件一定要包含补偿事件,否则无法运行,会抛出
org.flowable.common.engine.api.FlowableException: No execution found for sub process of boundary cancel event ***的
异常
:::
视频教程
取消结束事件