簡介
邊界事件:邊界事件屬於一種特殊的中間事件。
區別是: 中間事件 可以單獨作為流程元素存在於流程中,而 邊界事件 必須附屬於某個流程元素(如任務、子流程等)。邊界事件是Catching事件。
邊界出錯事件
說明
依附於子流程或者TASK上發生異常觸發事件。
本質上是捕獲BPMNError,如果配置了錯誤引用,則只會捕獲指定code,沒有則是捕獲全部
依附在任務上
1.記錄一個插曲,我是在任務辦理階段 想着拋出一BPMNError異常 以為就可以正常走邊界異常這條線
結果始終沒生效
委托類可以可以正常執行的 所以參考:org.flowable.engine.impl.bpmn.helper.ClassDelegate#execute
發現真正觸發邊界的是以下標紅的方法 當出現異常可以選擇是拋出還是走邊界異常。
try { activityBehaviorInstance.execute(execution); } catch (BpmnError error) { ErrorPropagation.propagateError(error, execution); } catch (RuntimeException e) { if (!ErrorPropagation.mapException(e, (ExecutionEntity) execution, mapExceptions)) throw e; }
針對某些api並沒有這樣的捕獲處理.所以自己定義,或者將來在最外層定義一個攔截器(必須最外層哦)。以下我的測試
必須最外層哦:比如我在ExecutinListener監聽器try catch。try cath因為走了異常邊界沒有往上拋異常 還是會繼續執行api辦理的后續流程。導致出錯。
最外層的意思就是以前那條線出現異常不能往下走,則嘗試走異常邊界
/** * 任務辦理 * @param completeReqDTO */ @Override @Transactional public void complete(CompleteReqDTO completeReqDTO) throws BusinessException {
//在flowable生命周期里面執行 processEngine.getProcessEngineConfiguration().getCommandExecutor().execute(new Command<Object>() { @SneakyThrows @Override public Object execute(CommandContext commandContext) { TaskStatusEnum taskStatusEnum = null; Task task = processEngine.getTaskService().createTaskQuery().taskId(completeReqDTO.getTaskId()).singleResult();; try { taskStatusEnum = TaskStatusEnum.convert.convert(completeReqDTO.getStatus()); } catch (Exception e) { log.error("枚舉轉換錯誤:{},{}", TaskStatusEnum.class, completeReqDTO.getStatus()); Execution execution = ExecutionHelper.getExecution(task.getExecutionId()); //走錯誤邊界事件 ErrorPropagation.propagateError(new BpmnError("aaa"), (ExecutionEntityImpl) execution); } if (taskStatusEnum == null) { throw new BusinessException(MessageFormatter.arrayFormat(ErrorCode.VALID_PARAMS_ERROR.getErrorMsg(), new String[]{"狀態不能為空"}).getMessage()); } processEngine.getTaskService().complete(task.getId(), completeReqDTO.getTaskVariables()); return null; } }); }
在flowable生命周期執行指的是 在執行我們的業務Command 之前會有一系列攔截器做初始化操作 比如Command.getContext();
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:flowable="http://flowable.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.flowable.org/processdef"> <process id="boundary_errorf_sub" name="錯誤邊界子流程" isExecutable="true"> <startEvent id="startEvent1"></startEvent> <userTask id="sid-87FCF890-845A-42F9-8B52-B40B80E1DA52" name="組員審批" flowable:assignee="組員1"> <extensionElements> <modeler:initiator-can-complete xmlns:modeler="http://flowable.org/modeler"><![CDATA[false]]></modeler:initiator-can-complete> </extensionElements> </userTask> <userTask id="sid-B779F5AA-1D99-4CBF-87C7-EBBAD03E9DEF" name="總監審批" flowable:assignee="總監1"> <extensionElements> <modeler:initiator-can-complete xmlns:modeler="http://flowable.org/modeler"><![CDATA[false]]></modeler:initiator-can-complete> </extensionElements> </userTask> <sequenceFlow id="sid-633CEB6F-601D-44E2-B3E4-1885C104CA1C" sourceRef="sid-87FCF890-845A-42F9-8B52-B40B80E1DA52" targetRef="sid-B779F5AA-1D99-4CBF-87C7-EBBAD03E9DEF"></sequenceFlow> <endEvent id="sid-5539B9CE-EDEA-461E-9806-FFC5CB50708D"></endEvent> <sequenceFlow id="sid-6EEA2922-F966-471A-A4E3-3BB10E721254" sourceRef="sid-B779F5AA-1D99-4CBF-87C7-EBBAD03E9DEF" targetRef="sid-5539B9CE-EDEA-461E-9806-FFC5CB50708D"></sequenceFlow> <userTask id="sid-FB858F22-0036-40DE-AC16-BD63E1BEF9F5" name="組長代審" flowable:assignee="組長1"> <extensionElements> <modeler:initiator-can-complete xmlns:modeler="http://flowable.org/modeler"><![CDATA[false]]></modeler:initiator-can-complete> </extensionElements> </userTask> <sequenceFlow id="sid-8996B76B-F7AA-4123-AC89-301D0147C402" name="超時" sourceRef="sid-8682C781-C10D-4DDF-9D61-9DBB6F72CD4A" targetRef="sid-FB858F22-0036-40DE-AC16-BD63E1BEF9F5"></sequenceFlow> <sequenceFlow id="sid-5DBFFFA3-B1DE-4557-9B7B-828CE658B3A4" sourceRef="sid-FB858F22-0036-40DE-AC16-BD63E1BEF9F5" targetRef="sid-B779F5AA-1D99-4CBF-87C7-EBBAD03E9DEF"></sequenceFlow> <boundaryEvent id="sid-8682C781-C10D-4DDF-9D61-9DBB6F72CD4A" attachedToRef="sid-87FCF890-845A-42F9-8B52-B40B80E1DA52" cancelActivity="true"> <timerEventDefinition> <timeDuration>PT5M</timeDuration> </timerEventDefinition> </boundaryEvent> <userTask id="sid-72ABD643-8FDF-4364-B36A-B204ECD23250" name="發起人填表" flowable:assignee="小王"> <extensionElements> <modeler:initiator-can-complete xmlns:modeler="http://flowable.org/modeler"><![CDATA[false]]></modeler:initiator-can-complete> </extensionElements> </userTask> <sequenceFlow id="sid-91282A7D-131A-4010-8A34-61B09A97974E" sourceRef="startEvent1" targetRef="sid-72ABD643-8FDF-4364-B36A-B204ECD23250"></sequenceFlow> <sequenceFlow id="sid-D660D588-A664-4B39-8CC2-5A7EFA14A2B3" sourceRef="sid-72ABD643-8FDF-4364-B36A-B204ECD23250" targetRef="sid-87FCF890-845A-42F9-8B52-B40B80E1DA52"></sequenceFlow> </process> <bpmndi:BPMNDiagram id="BPMNDiagram_boundary_errorf_sub"> <bpmndi:BPMNPlane bpmnElement="boundary_errorf_sub" id="BPMNPlane_boundary_errorf_sub"> <bpmndi:BPMNShape bpmnElement="startEvent1" id="BPMNShape_startEvent1"> <omgdc:Bounds height="30.0" width="30.0" x="0.0" y="160.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="sid-87FCF890-845A-42F9-8B52-B40B80E1DA52" id="BPMNShape_sid-87FCF890-845A-42F9-8B52-B40B80E1DA52"> <omgdc:Bounds height="80.0" width="100.0" x="345.0" y="135.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="sid-B779F5AA-1D99-4CBF-87C7-EBBAD03E9DEF" id="BPMNShape_sid-B779F5AA-1D99-4CBF-87C7-EBBAD03E9DEF"> <omgdc:Bounds height="80.0" width="100.0" x="525.0" y="135.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="sid-5539B9CE-EDEA-461E-9806-FFC5CB50708D" id="BPMNShape_sid-5539B9CE-EDEA-461E-9806-FFC5CB50708D"> <omgdc:Bounds height="28.0" width="28.0" x="670.0" y="161.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="sid-FB858F22-0036-40DE-AC16-BD63E1BEF9F5" id="BPMNShape_sid-FB858F22-0036-40DE-AC16-BD63E1BEF9F5"> <omgdc:Bounds height="80.0" width="100.0" x="375.0" y="300.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="sid-8682C781-C10D-4DDF-9D61-9DBB6F72CD4A" id="BPMNShape_sid-8682C781-C10D-4DDF-9D61-9DBB6F72CD4A"> <omgdc:Bounds height="31.0" width="31.0" x="355.01441312765667" y="199.90121833936652"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="sid-72ABD643-8FDF-4364-B36A-B204ECD23250" id="BPMNShape_sid-72ABD643-8FDF-4364-B36A-B204ECD23250"> <omgdc:Bounds height="80.0" width="100.0" x="150.0" y="135.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNEdge bpmnElement="sid-633CEB6F-601D-44E2-B3E4-1885C104CA1C" id="BPMNEdge_sid-633CEB6F-601D-44E2-B3E4-1885C104CA1C"> <omgdi:waypoint x="444.9499999999431" y="175.0"></omgdi:waypoint> <omgdi:waypoint x="524.9999999999723" y="175.0"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="sid-5DBFFFA3-B1DE-4557-9B7B-828CE658B3A4" id="BPMNEdge_sid-5DBFFFA3-B1DE-4557-9B7B-828CE658B3A4"> <omgdi:waypoint x="474.95000000000005" y="340.0"></omgdi:waypoint> <omgdi:waypoint x="575.0" y="340.0"></omgdi:waypoint> <omgdi:waypoint x="575.0" y="214.95000000000002"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="sid-6EEA2922-F966-471A-A4E3-3BB10E721254" id="BPMNEdge_sid-6EEA2922-F966-471A-A4E3-3BB10E721254"> <omgdi:waypoint x="624.949999999996" y="175.0"></omgdi:waypoint> <omgdi:waypoint x="670.0" y="175.0"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="sid-D660D588-A664-4B39-8CC2-5A7EFA14A2B3" id="BPMNEdge_sid-D660D588-A664-4B39-8CC2-5A7EFA14A2B3"> <omgdi:waypoint x="249.94999999986936" y="175.0"></omgdi:waypoint> <omgdi:waypoint x="344.9999999999363" y="175.0"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="sid-8996B76B-F7AA-4123-AC89-301D0147C402" id="BPMNEdge_sid-8996B76B-F7AA-4123-AC89-301D0147C402"> <omgdi:waypoint x="372.8906195078865" y="231.74010984107392"></omgdi:waypoint> <omgdi:waypoint x="376.0" y="257.99453814261057"></omgdi:waypoint> <omgdi:waypoint x="425.0" y="257.99453814261057"></omgdi:waypoint> <omgdi:waypoint x="425.0" y="300.0"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="sid-91282A7D-131A-4010-8A34-61B09A97974E" id="BPMNEdge_sid-91282A7D-131A-4010-8A34-61B09A97974E"> <omgdi:waypoint x="29.94999946593476" y="175.0"></omgdi:waypoint> <omgdi:waypoint x="150.0" y="175.0"></omgdi:waypoint> </bpmndi:BPMNEdge> </bpmndi:BPMNPlane> </bpmndi:BPMNDiagram> </definitions>
依附在子流程上
子流程執行過程中拋出BPMNError異常,也可以通過異常結束事件觸發
定時邊界事件
說明
任務到了指定事件沒有辦理執行邊界,適用於超時任務 注:需要開啟springProcessEngineConfiguration.setAsyncExecutorActivate(true);異步執行開關
依附在任務上
5分鍾超時由組長代審,當執行到組員審批同時會執行一條job任務可以觀察此表 act_ru_timer_job
超時后執行了定時邊界這條線job會刪除
未超時任務被辦理了此job也會被刪除
取消任務指的是,當執行邊界事件當前任務沒有辦理是否取消
<boundaryEvent id="sid-8682C781-C10D-4DDF-9D61-9DBB6F72CD4A" cancelActivity="true"> <timerEventDefinition> <timeDate>PT5M</timeDate> </timerEventDefinition> </boundaryEvent>
相關參數
可以參考:https://www.cnblogs.com/LQBlog/p/15813380.html#autoid-3-2-0
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:flowable="http://flowable.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.flowable.org/processdef"> <process id="boundary_errorf_sub" name="錯誤邊界子流程" isExecutable="true"> <startEvent id="startEvent1"></startEvent> <userTask id="sid-87FCF890-845A-42F9-8B52-B40B80E1DA52" name="組員審批"></userTask> <sequenceFlow id="sid-5FA93B8F-FFF3-47B1-B6BB-390D37E22AC5" sourceRef="startEvent1" targetRef="sid-87FCF890-845A-42F9-8B52-B40B80E1DA52"></sequenceFlow> <userTask id="sid-B779F5AA-1D99-4CBF-87C7-EBBAD03E9DEF" name="總監審批"></userTask> <sequenceFlow id="sid-633CEB6F-601D-44E2-B3E4-1885C104CA1C" sourceRef="sid-87FCF890-845A-42F9-8B52-B40B80E1DA52" targetRef="sid-B779F5AA-1D99-4CBF-87C7-EBBAD03E9DEF"></sequenceFlow> <endEvent id="sid-5539B9CE-EDEA-461E-9806-FFC5CB50708D"></endEvent> <sequenceFlow id="sid-6EEA2922-F966-471A-A4E3-3BB10E721254" sourceRef="sid-B779F5AA-1D99-4CBF-87C7-EBBAD03E9DEF" targetRef="sid-5539B9CE-EDEA-461E-9806-FFC5CB50708D"></sequenceFlow> <boundaryEvent id="sid-8682C781-C10D-4DDF-9D61-9DBB6F72CD4A" cancelActivity="true"> <timerEventDefinition> <timeDate>PT5M</timeDate> </timerEventDefinition> </boundaryEvent> <userTask id="sid-FB858F22-0036-40DE-AC16-BD63E1BEF9F5" name="組長代審"></userTask> <sequenceFlow id="sid-8996B76B-F7AA-4123-AC89-301D0147C402" name="超時" sourceRef="sid-8682C781-C10D-4DDF-9D61-9DBB6F72CD4A" targetRef="sid-FB858F22-0036-40DE-AC16-BD63E1BEF9F5"></sequenceFlow> <sequenceFlow id="sid-5DBFFFA3-B1DE-4557-9B7B-828CE658B3A4" sourceRef="sid-FB858F22-0036-40DE-AC16-BD63E1BEF9F5" targetRef="sid-B779F5AA-1D99-4CBF-87C7-EBBAD03E9DEF"></sequenceFlow> </process> <bpmndi:BPMNDiagram id="BPMNDiagram_boundary_errorf_sub"> <bpmndi:BPMNPlane bpmnElement="boundary_errorf_sub" id="BPMNPlane_boundary_errorf_sub"> <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-87FCF890-845A-42F9-8B52-B40B80E1DA52" id="BPMNShape_sid-87FCF890-845A-42F9-8B52-B40B80E1DA52"> <omgdc:Bounds height="80.0" width="100.0" x="165.0" y="135.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="sid-B779F5AA-1D99-4CBF-87C7-EBBAD03E9DEF" id="BPMNShape_sid-B779F5AA-1D99-4CBF-87C7-EBBAD03E9DEF"> <omgdc:Bounds height="80.0" width="100.0" x="345.0" y="135.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="sid-5539B9CE-EDEA-461E-9806-FFC5CB50708D" id="BPMNShape_sid-5539B9CE-EDEA-461E-9806-FFC5CB50708D"> <omgdc:Bounds height="28.0" width="28.0" x="490.0" y="161.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="sid-8682C781-C10D-4DDF-9D61-9DBB6F72CD4A" id="BPMNShape_sid-8682C781-C10D-4DDF-9D61-9DBB6F72CD4A"> <omgdc:Bounds height="31.0" width="31.0" x="180.0" y="195.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="sid-FB858F22-0036-40DE-AC16-BD63E1BEF9F5" id="BPMNShape_sid-FB858F22-0036-40DE-AC16-BD63E1BEF9F5"> <omgdc:Bounds height="80.0" width="100.0" x="195.0" y="300.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNEdge bpmnElement="sid-633CEB6F-601D-44E2-B3E4-1885C104CA1C" id="BPMNEdge_sid-633CEB6F-601D-44E2-B3E4-1885C104CA1C"> <omgdi:waypoint x="264.9499999999431" y="175.0"></omgdi:waypoint> <omgdi:waypoint x="345.0" y="175.0"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="sid-5FA93B8F-FFF3-47B1-B6BB-390D37E22AC5" id="BPMNEdge_sid-5FA93B8F-FFF3-47B1-B6BB-390D37E22AC5"> <omgdi:waypoint x="129.94340692927761" y="177.55019845363262"></omgdi:waypoint> <omgdi:waypoint x="164.99999999999906" y="176.4985"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="sid-5DBFFFA3-B1DE-4557-9B7B-828CE658B3A4" id="BPMNEdge_sid-5DBFFFA3-B1DE-4557-9B7B-828CE658B3A4"> <omgdi:waypoint x="294.9499999998728" y="340.0"></omgdi:waypoint> <omgdi:waypoint x="395.0" y="340.0"></omgdi:waypoint> <omgdi:waypoint x="395.0" y="214.95000000000002"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="sid-6EEA2922-F966-471A-A4E3-3BB10E721254" id="BPMNEdge_sid-6EEA2922-F966-471A-A4E3-3BB10E721254"> <omgdi:waypoint x="444.95000000000005" y="175.0"></omgdi:waypoint> <omgdi:waypoint x="490.0" y="175.0"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="sid-8996B76B-F7AA-4123-AC89-301D0147C402" id="BPMNEdge_sid-8996B76B-F7AA-4123-AC89-301D0147C402"> <omgdi:waypoint x="196.0" y="226.94999118403769"></omgdi:waypoint> <omgdi:waypoint x="196.0" y="257.99453814261057"></omgdi:waypoint> <omgdi:waypoint x="245.0" y="257.99453814261057"></omgdi:waypoint> <omgdi:waypoint x="245.0" y="300.0"></omgdi:waypoint> </bpmndi:BPMNEdge> </bpmndi:BPMNPlane> </bpmndi:BPMNDiagram> </definitions>
依附在子流程上
同理,子流程未完結觸發超時任務
邊界信號事件
說明
該事件接收到指定的信號后觸發,不同的是信號事件可以定義成全局的也可以額定義成流程實例作用范圍,相同作用於一處發信號,所有信號的邊界事件都能接收
信號配置以及啟動可以參考《flowable-流程中心設計之開始事件(三)》
設計
邊界消息事件
配置以及發布消息參考:https://www.cnblogs.com/LQBlog/p/15813380.html#autoid-4-5-0
設計設信號事件一直 只是信號替換成消息
設計
邊界取消事件
說明
配合子流程使用 可參考https://www.cnblogs.com/LQBlog/p/15816934.html#autoid-4-3-0
設計
補償邊界事件
說明
補償邊界事件與其他邊界事件的策略不同。 其他邊界事件(比如信號邊界事件)當到達關聯的節點就會被激活。 離開節點時,就會掛起,對應的事件訂閱也會取消。 補償邊界事件則不同。補償邊界事件在關聯的節點成功完成時激活。 當補償事件觸發或對應流程實例結束時,事件訂閱才會刪除。
觸發補償事件的2種情況
補償邊界事件的觸發有兩種情況:
1. 事務子流程被取消時,會觸發事務子流程里面的補償邊界事件。
2. 使用補償中間事件來觸發,需要時Throwing事件。
特性
- 當補償中間事件觸發時,會觸發當前執行流中的補償Catching事件,如果補償邊界事件依附的節點是多實例的,那么補償事件也會觸發多次。
- 補償的執行順序會按照倒敘進行補償。
- 只會補償已經完成的任務,還沒有完成的任務補償邊界事件是不會觸發的。
設計