百度360必应搜狗淘宝本站头条
当前位置:网站首页 > 编程网 > 正文

Flowable事件-错误事件 flowable event

yuyutoo 2024-10-21 12:14 2 浏览 0 评论

在这里插入图片描述

Flowable事件之错误事件

??错误事件可以用做一个流程的开始事件或者作为一个任务或者子流程的边界事件,错误事件没有提供作用中间事件的功能,这一点和前面介绍的定时器事件和消息事件还有区别的。

1.开始事件

??错误启动事件(error start event),可用于触发事件子流程(Event Sub-Process)。错误启动事件不能用于启动流程实例

错误启动事件总是中断。我们通过案例来介绍。此处我们用Eclipse来绘制流程图,熟悉下Eclipse工具

在这里插入图片描述

注意:绘制的是子流程事件:

在这里插入图片描述

然后我们再定义一个错误,内容为:

<error id="error01" errorCode="abcd">

在FlowableUI中没找到错误定义的选项,我们就在流程文件中自己添加即可。

在这里插入图片描述

在这里插入图片描述

完整的流程文件

<?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">
  <error id="error01" errorCode="abcd"></error>
  <process id="myProcess" name="My process" isExecutable="true">
    <startEvent id="startevent1" name="Start"></startEvent>
    <serviceTask id="servicetask1" name="自动任务一" activiti:class="com.bobo.delegate.MyOneDelegate"></serviceTask>
    <sequenceFlow id="flow1" sourceRef="startevent1" targetRef="servicetask1"></sequenceFlow>
    <endEvent id="endevent1" name="End"></endEvent>
    <sequenceFlow id="flow2" sourceRef="servicetask1" targetRef="endevent1"></sequenceFlow>
    <subProcess id="eventsubprocess1" name="Event sub Process" triggeredByEvent="true">
      <startEvent id="errorstartevent1" name="Error start">
        <errorEventDefinition errorRef="error01"></errorEventDefinition>
      </startEvent>
      <serviceTask id="servicetask2" name="自动任务二" activiti:class="com.bobo.delegate.MyTwoDelegate"></serviceTask>
      <endEvent id="endevent2" name="End"></endEvent>
      <sequenceFlow id="flow3" sourceRef="servicetask2" targetRef="endevent2"></sequenceFlow>
      <sequenceFlow id="flow4" sourceRef="errorstartevent1" targetRef="servicetask2"></sequenceFlow>
    </subProcess>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_myProcess">
    <bpmndi:BPMNPlane bpmnElement="myProcess" id="BPMNPlane_myProcess">
      <bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
        <omgdc:Bounds height="35.0" width="35.0" x="480.0" y="260.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="servicetask1" id="BPMNShape_servicetask1">
        <omgdc:Bounds height="55.0" width="105.0" x="710.0" y="250.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
        <omgdc:Bounds height="35.0" width="35.0" x="930.0" y="260.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="eventsubprocess1" id="BPMNShape_eventsubprocess1">
        <omgdc:Bounds height="211.0" width="401.0" x="530.0" y="420.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="errorstartevent1" id="BPMNShape_errorstartevent1">
        <omgdc:Bounds height="35.0" width="35.0" x="600.0" y="520.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="servicetask2" id="BPMNShape_servicetask2">
        <omgdc:Bounds height="55.0" width="105.0" x="700.0" y="510.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="endevent2" id="BPMNShape_endevent2">
        <omgdc:Bounds height="35.0" width="35.0" x="850.0" y="520.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
        <omgdi:waypoint x="515.0" y="277.0"></omgdi:waypoint>
        <omgdi:waypoint x="710.0" y="277.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
        <omgdi:waypoint x="815.0" y="277.0"></omgdi:waypoint>
        <omgdi:waypoint x="930.0" y="277.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3">
        <omgdi:waypoint x="805.0" y="537.0"></omgdi:waypoint>
        <omgdi:waypoint x="850.0" y="537.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow4" id="BPMNEdge_flow4">
        <omgdi:waypoint x="635.0" y="537.0"></omgdi:waypoint>
        <omgdi:waypoint x="700.0" y="537.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>

然后我们在主流程中的自动任务一中我们抛出异常

public class MyOneDelegate implements JavaDelegate {
    @Override
    public void execute(DelegateExecution execution) {

        System.out.println("完成自动审批任务-----》MyOneDelegate" + LocalDateTime.now().toString());
        // 业务执行发现有问题 此处的errorCode需要和定义的error标签中的errorCode保持一致
        throw new BpmnError("abcd");
    }
}

然后我们在自定义任务二中简单定义一个输出即可。然后我们部署任务

    @Test
    public void test01() throws Exception{
        ZipInputStream in = new ZipInputStream(SpringBootFlowableApplicationTests.class.getClassLoader().getResourceAsStream("错误启动事件.bar"));
        Deployment deployment = processEngine.getRepositoryService().createDeployment()
                .addZipInputStream(in)
                .name("错误启动事件")
                .deploy();
        System.out.println("-----");
    }

然后我们再启动流程实例,那么自动任务一就会抛出异常,然后对应的子流程就会开始

    /**
     * 启动流程实例
     *
     */
    @Test
    public void startProcessInstanceByKey()  throws Exception{

        processEngine.getRuntimeService()
                .startProcessInstanceById("myProcess:1:c0462994-af79-11ec-8cae-c03c59ad2248");
        System.out.println("开始启动的时间:" + LocalDateTime.now().toString());
        // 需要在此阻塞比等待长的时间
        TimeUnit.MINUTES.sleep(3);
    }

输出结果获取到了我们期望的结果

通过输出结果也可以看到执行的自动任务一后,抛出错误事件abcd,子流程触发并执行了。

在这里插入图片描述

2.边界事件

定义如下的流程图:

在这里插入图片描述

注意绘制的时候

在这里插入图片描述

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">
    <error id="error02" errorCode="a123" ></error>
    <process id="myProcess" name="My process" isExecutable="true">
        <startEvent id="startevent1" name="Start"></startEvent>
        <serviceTask id="servicetask2" name="自动任务二" activiti:class="com.bobo.delegate.MyTwoDelegate"></serviceTask>
        <serviceTask id="servicetask3" name="自动任务三" activiti:class="com.bobo.delegate.MyThreeDelegate"></serviceTask>
        <endEvent id="endevent2" name="End"></endEvent>
        <sequenceFlow id="flow5" sourceRef="servicetask2" targetRef="endevent2"></sequenceFlow>
        <endEvent id="endevent3" name="End"></endEvent>
        <sequenceFlow id="flow6" sourceRef="servicetask3" targetRef="endevent3"></sequenceFlow>
        <subProcess id="subprocess1" name="Sub Process">
            <startEvent id="startevent2" name="Start"></startEvent>
            <serviceTask id="servicetask4" name="Service Task" activiti:class="com.bobo.delegate.MyOneDelegate"></serviceTask>
            <endEvent id="endevent4" name="End"></endEvent>
            <sequenceFlow id="flow10" sourceRef="servicetask4" targetRef="endevent4"></sequenceFlow>
            <sequenceFlow id="flow11" sourceRef="startevent2" targetRef="servicetask4"></sequenceFlow>
        </subProcess>
        <sequenceFlow id="flow8" sourceRef="startevent1" targetRef="subprocess1"></sequenceFlow>
        <sequenceFlow id="flow9" sourceRef="subprocess1" targetRef="servicetask2"></sequenceFlow>
        <boundaryEvent id="boundaryerror1" name="Error" attachedToRef="subprocess1">
            <errorEventDefinition errorRef="error02"></errorEventDefinition>
        </boundaryEvent>
        <sequenceFlow id="flow12" sourceRef="boundaryerror1" targetRef="servicetask3"></sequenceFlow>
    </process>
    <bpmndi:BPMNDiagram id="BPMNDiagram_myProcess">
        <bpmndi:BPMNPlane bpmnElement="myProcess" id="BPMNPlane_myProcess">
            <bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
                <omgdc:Bounds height="35.0" width="35.0" x="402.0" y="388.0"></omgdc:Bounds>
            </bpmndi:BPMNShape>
            <bpmndi:BPMNShape bpmnElement="servicetask2" id="BPMNShape_servicetask2">
                <omgdc:Bounds height="55.0" width="105.0" x="1285.0" y="368.0"></omgdc:Bounds>
            </bpmndi:BPMNShape>
            <bpmndi:BPMNShape bpmnElement="servicetask3" id="BPMNShape_servicetask3">
                <omgdc:Bounds height="55.0" width="105.0" x="1099.0" y="590.0"></omgdc:Bounds>
            </bpmndi:BPMNShape>
            <bpmndi:BPMNShape bpmnElement="endevent2" id="BPMNShape_endevent2">
                <omgdc:Bounds height="35.0" width="35.0" x="1440.0" y="378.0"></omgdc:Bounds>
            </bpmndi:BPMNShape>
            <bpmndi:BPMNShape bpmnElement="endevent3" id="BPMNShape_endevent3">
                <omgdc:Bounds height="35.0" width="35.0" x="1320.0" y="600.0"></omgdc:Bounds>
            </bpmndi:BPMNShape>
            <bpmndi:BPMNShape bpmnElement="subprocess1" id="BPMNShape_subprocess1">
                <omgdc:Bounds height="271.0" width="451.0" x="660.0" y="270.0"></omgdc:Bounds>
            </bpmndi:BPMNShape>
            <bpmndi:BPMNShape bpmnElement="startevent2" id="BPMNShape_startevent2">
                <omgdc:Bounds height="35.0" width="35.0" x="720.0" y="390.0"></omgdc:Bounds>
            </bpmndi:BPMNShape>
            <bpmndi:BPMNShape bpmnElement="servicetask4" id="BPMNShape_servicetask4">
                <omgdc:Bounds height="55.0" width="105.0" x="850.0" y="381.0"></omgdc:Bounds>
            </bpmndi:BPMNShape>
            <bpmndi:BPMNShape bpmnElement="endevent4" id="BPMNShape_endevent4">
                <omgdc:Bounds height="35.0" width="35.0" x="1030.0" y="391.0"></omgdc:Bounds>
            </bpmndi:BPMNShape>
            <bpmndi:BPMNShape bpmnElement="boundaryerror1" id="BPMNShape_boundaryerror1">
                <omgdc:Bounds height="30.0" width="30.0" x="950.0" y="520.0"></omgdc:Bounds>
            </bpmndi:BPMNShape>
            <bpmndi:BPMNEdge bpmnElement="flow5" id="BPMNEdge_flow5">
                <omgdi:waypoint x="1390.0" y="395.0"></omgdi:waypoint>
                <omgdi:waypoint x="1440.0" y="395.0"></omgdi:waypoint>
            </bpmndi:BPMNEdge>
            <bpmndi:BPMNEdge bpmnElement="flow6" id="BPMNEdge_flow6">
                <omgdi:waypoint x="1204.0" y="617.0"></omgdi:waypoint>
                <omgdi:waypoint x="1320.0" y="617.0"></omgdi:waypoint>
            </bpmndi:BPMNEdge>
            <bpmndi:BPMNEdge bpmnElement="flow10" id="BPMNEdge_flow10">
                <omgdi:waypoint x="955.0" y="408.0"></omgdi:waypoint>
                <omgdi:waypoint x="1030.0" y="408.0"></omgdi:waypoint>
            </bpmndi:BPMNEdge>
            <bpmndi:BPMNEdge bpmnElement="flow11" id="BPMNEdge_flow11">
                <omgdi:waypoint x="755.0" y="407.0"></omgdi:waypoint>
                <omgdi:waypoint x="850.0" y="408.0"></omgdi:waypoint>
            </bpmndi:BPMNEdge>
            <bpmndi:BPMNEdge bpmnElement="flow8" id="BPMNEdge_flow8">
                <omgdi:waypoint x="437.0" y="405.0"></omgdi:waypoint>
                <omgdi:waypoint x="660.0" y="405.0"></omgdi:waypoint>
            </bpmndi:BPMNEdge>
            <bpmndi:BPMNEdge bpmnElement="flow9" id="BPMNEdge_flow9">
                <omgdi:waypoint x="1111.0" y="405.0"></omgdi:waypoint>
                <omgdi:waypoint x="1285.0" y="395.0"></omgdi:waypoint>
            </bpmndi:BPMNEdge>
            <bpmndi:BPMNEdge bpmnElement="flow12" id="BPMNEdge_flow12">
                <omgdi:waypoint x="965.0" y="550.0"></omgdi:waypoint>
                <omgdi:waypoint x="964.0" y="617.0"></omgdi:waypoint>
                <omgdi:waypoint x="1099.0" y="617.0"></omgdi:waypoint>
            </bpmndi:BPMNEdge>
        </bpmndi:BPMNPlane>
    </bpmndi:BPMNDiagram>
</definitions>

对应的三个自定义任务绑定的JavaDelegate为:

public class MyOneDelegate implements JavaDelegate {
    @Override
    public void execute(DelegateExecution execution) {

        System.out.println("完成自动审批任务-----》MyOneDelegate" + LocalDateTime.now().toString());
        // 业务执行发现有问题 此处的errorCode需要和定义的error标签中的errorCode保持一致
        throw new BpmnError("a123");
    }
}

public class MyTwoDelegate implements JavaDelegate {
    @Override
    public void execute(DelegateExecution execution) {
        System.out.println("MyTwoDelegate---->执行了" + LocalDateTime.now().toString());
    }
}

public class MyThreeDelegate implements JavaDelegate {
    @Override
    public void execute(DelegateExecution execution) {
        System.out.println("MyThreeDelegate---->执行了" + LocalDateTime.now().toString());
    }
}

然后我们部署文件

    @Test
    public void test01() throws Exception{
        ZipInputStream in = new ZipInputStream(SpringBootFlowableApplicationTests.class
                .getClassLoader()
                .getResourceAsStream("错误边界事件.bar"));
        Deployment deployment = processEngine.getRepositoryService().createDeployment()
                .addZipInputStream(in)
                .name("错误边界事件")
                .deploy();
        System.out.println("-----");
    }

部署成功后我们再启动一个流程实例,进入到自定义任务一处会抛出异常,触发边界异常处理

在这里插入图片描述

输出的结果和我们预期的是一样的

相关推荐

史上最全的浏览器兼容性问题和解决方案

微信ID:WEB_wysj(点击关注)◎◎◎◎◎◎◎◎◎一┳═┻︻▄(页底留言开放,欢迎来吐槽)●●●...

平面设计基础知识_平面设计基础知识实验收获与总结
平面设计基础知识_平面设计基础知识实验收获与总结

CSS构造颜色,背景与图像1.使用span更好的控制文本中局部区域的文本:文本;2.使用display属性提供区块转变:display:inline(是内联的...

2025-02-21 16:01 yuyutoo

写作排版简单三步就行-工具篇_作文排版模板

和我们工作中日常word排版内部交流不同,这篇教程介绍的写作排版主要是用于“微信公众号、头条号”网络展示。写作展现的是我的思考,排版是让写作在网格上更好地展现。在写作上花费时间是有累积复利优势的,在排...

写一个2048的游戏_2048小游戏功能实现

1.创建HTML文件1.打开一个文本编辑器,例如Notepad++、SublimeText、VisualStudioCode等。2.将以下HTML代码复制并粘贴到文本编辑器中:html...

今天你穿“短袖”了吗?青岛最高23℃!接下来几天气温更刺激……

  最近的天气暖和得让很多小伙伴们喊“热”!!!  昨天的气温到底升得有多高呢?你家有没有榜上有名?...

CSS不规则卡片,纯CSS制作优惠券样式,CSS实现锯齿样式

之前也有写过CSS优惠券样式《CSS3径向渐变实现优惠券波浪造型》,这次再来温习一遍,并且将更为详细的讲解,从布局到具体样式说明,最后定义CSS变量,自定义主题颜色。布局...

柠檬科技肖勃飞:大数据风控助力信用社会建设

...

你的自我界限够强大吗?_你的自我界限够强大吗英文

我的结果:A、该设立新的界限...

行内元素与块级元素,以及区别_行内元素和块级元素有什么区别?

行内元素与块级元素首先,CSS规范规定,每个元素都有display属性,确定该元素的类型,每个元素都有默认的display值,分别为块级(block)、行内(inline)。块级元素:(以下列举比较常...

让“成都速度”跑得潇潇洒洒,地上地下共享轨交繁华
让“成都速度”跑得潇潇洒洒,地上地下共享轨交繁华

去年的两会期间,习近平总书记在参加人大会议四川代表团审议时,对治蜀兴川提出了明确要求,指明了前行方向,并带来了“祝四川人民的生活越来越安逸”的美好祝福。又是一年...

2025-02-21 16:00 yuyutoo

今年国家综合性消防救援队伍计划招录消防员15000名

记者24日从应急管理部获悉,国家综合性消防救援队伍2023年消防员招录工作已正式启动。今年共计划招录消防员15000名,其中高校应届毕业生5000名、退役士兵5000名、社会青年5000名。本次招录的...

一起盘点最新 Chrome v133 的5大主流特性 ?

1.CSS的高级attr()方法CSSattr()函数是CSSLevel5中用于检索DOM元素的属性值并将其用于CSS属性值,类似于var()函数替换自定义属性值的方式。...

竞走团体世锦赛5月太仓举行 世界冠军杨家玉担任形象大使

style="text-align:center;"data-mce-style="text-align:...

学物理能做什么?_学物理能做什么 卢昌海

作者:曹则贤中国科学院物理研究所原标题:《物理学:ASourceofPowerforMan》在2006年中央电视台《对话》栏目的某期节目中,主持人问过我一个的问题:“学物理的人,如果日后不...

你不知道的关于这只眯眼兔的6个小秘密
你不知道的关于这只眯眼兔的6个小秘密

在你们忙着给熊本君做表情包的时候,要知道,最先在网络上引起轰动的可是这只脸上只有两条缝的兔子——兔斯基。今年,它更是迎来了自己的10岁生日。①关于德艺双馨“老艺...

2025-02-21 16:00 yuyutoo

取消回复欢迎 发表评论: