【第十五篇】Flowable事件-信号事件

举报
波波烤鸭 发表于 2022/04/10 00:44:15 2022/04/10
【摘要】 Flowable中的信号事件 1.开始事件 然后设置相关的属性,并定义一个信号 然后在我们声明的信号开始引用我们上面创建的信号 完整的xml文件 <?xml version=...

在这里插入图片描述

Flowable中的信号事件

1.开始事件

在这里插入图片描述

然后设置相关的属性,并定义一个信号
在这里插入图片描述

然后在我们声明的信号开始引用我们上面创建的信号

在这里插入图片描述

完整的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" exporter="Flowable Open Source Modeler" exporterVersion="6.7.2">
  <signal id="signal01" name="firstSignal" flowable:scope="global"></signal>
  <process id="event2001" name="信号启动事件" isExecutable="true">
    <startEvent id="start01" name="信号开始" isInterrupting="true">
      <signalEventDefinition signalRef="signal01"></signalEventDefinition>
    </startEvent>
    <serviceTask id="task1" name="自动任务" flowable:class="com.bobo.flow.delegate.MyTwoJavaDelegate"></serviceTask>
    <endEvent id="end01" name="结束"></endEvent>
    <sequenceFlow id="sid-0FF05CCE-85CB-416C-8D36-A935AF9586C2" sourceRef="task1" targetRef="end01"></sequenceFlow>
    <sequenceFlow id="sid-C8AD1AEE-5FCB-4419-8596-74532DD71ABC" sourceRef="start01" targetRef="task1"></sequenceFlow>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_event2001">
    <bpmndi:BPMNPlane bpmnElement="event2001" id="BPMNPlane_event2001">
      <bpmndi:BPMNShape bpmnElement="start01" id="BPMNShape_start01">
        <omgdc:Bounds height="30.0" width="30.0" x="285.0" y="172.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="task1" id="BPMNShape_task1">
        <omgdc:Bounds height="80.0" width="100.0" x="467.5" y="147.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="end01" id="BPMNShape_end01">
        <omgdc:Bounds height="28.0" width="28.0" x="612.5" y="173.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="sid-C8AD1AEE-5FCB-4419-8596-74532DD71ABC" id="BPMNEdge_sid-C8AD1AEE-5FCB-4419-8596-74532DD71ABC" flowable:sourceDockerX="15.0" flowable:sourceDockerY="15.0" flowable:targetDockerX="50.0" flowable:targetDockerY="40.0">
        <omgdi:waypoint x="314.94999961358405" y="187.0"></omgdi:waypoint>
        <omgdi:waypoint x="467.4999999999399" y="187.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-0FF05CCE-85CB-416C-8D36-A935AF9586C2" id="BPMNEdge_sid-0FF05CCE-85CB-416C-8D36-A935AF9586C2" flowable:sourceDockerX="50.0" flowable:sourceDockerY="40.0" flowable:targetDockerX="14.0" flowable:targetDockerY="14.0">
        <omgdi:waypoint x="567.449999999996" y="187.0"></omgdi:waypoint>
        <omgdi:waypoint x="612.5" y="187.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>

部署流程:

   /**
     * Deploy
     */
    @Test
    void testDeploy() throws Exception {
        //RepositoryService repositoryService = processEngine.getRepositoryService();
        Deployment deploy = repositoryService.createDeployment()
                .addClasspathResource("信号启动事件.bpmn20.xml")
                .name("信号启动事件")
                .deploy();
        System.out.println("deploy.getId() = " + deploy.getId());
        System.out.println("deploy.getName() = " + deploy.getName());
        System.out.println("部署开始的时间:" + new Date());
        //TimeUnit.MINUTES.sleep(3);
    }

流程是一个信息启动事件,所以我们需要释放对应的信号来触发流程的启动

    /**
     * 通过信号发送来触发信号启动事件的执行
     * 全局的信息
     */
    @Test
    void signalReceived() throws Exception {
        runtimeService.signalEventReceived("firstSignal");
        // 我们得保证容器的运行,所以需要阻塞
        TimeUnit.MINUTES.sleep(1);
    }

通过输出语句可以看到自定义任务触发了
在这里插入图片描述

我们可以把信息的作用域由原来的golbal全局的调整为processInstance,测试后发现还是执行了,说明在启动事件信息的作用域其实是不起作用的。

  <signal id="signal01" name="firstSignal" flowable:scope="processInstance"></signal>

2.中间捕获事件

案例如下:当我们启动事件后,会阻塞在这个消息获取中间事件处,等待相关信号后才会继续流转。
在这里插入图片描述

对应的信号绑定

<?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" exporter="Flowable Open Source Modeler" exporterVersion="6.7.2">
  <signal id="singnal02" name="secondSingal" flowable:scope="global"></signal>
  <process id="event2002" name="信号中间捕获事件" isExecutable="true">
    <startEvent id="start01" name="开始" flowable:formFieldValidation="true"></startEvent>
    <intermediateCatchEvent id="signal01" name="信号捕获中间事件">
      <signalEventDefinition signalRef="singnal02"></signalEventDefinition>
    </intermediateCatchEvent>
    <sequenceFlow id="sid-FBD95BC3-BA38-4863-95E6-E7D484FE80CB" sourceRef="start01" targetRef="signal01"></sequenceFlow>
    <serviceTask id="task01" name="自动任务" flowable:class="com.bobo.flow.delegate.MyTwoJavaDelegate"></serviceTask>
    <sequenceFlow id="sid-BF5FB671-5895-4FAC-8F92-E4BC4DEE821A" sourceRef="signal01" targetRef="task01"></sequenceFlow>
    <endEvent id="end01" name="结束任务"></endEvent>
    <sequenceFlow id="sid-4F4853C5-0FE6-48AB-BD80-A37CF807D90D" sourceRef="task01" targetRef="end01"></sequenceFlow>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_event2002">
    <bpmndi:BPMNPlane bpmnElement="event2002" id="BPMNPlane_event2002">
      <bpmndi:BPMNShape bpmnElement="start01" id="BPMNShape_start01">
        <omgdc:Bounds height="30.0" width="30.0" x="120.0" y="150.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="signal01" id="BPMNShape_signal01">
        <omgdc:Bounds height="30.0" width="30.0" x="318.5" y="150.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="task01" id="BPMNShape_task01">
        <omgdc:Bounds height="80.0" width="100.0" x="495.5" y="122.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="end01" id="BPMNShape_end01">
        <omgdc:Bounds height="28.0" width="28.0" x="690.0" y="151.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="sid-BF5FB671-5895-4FAC-8F92-E4BC4DEE821A" id="BPMNEdge_sid-BF5FB671-5895-4FAC-8F92-E4BC4DEE821A" flowable:sourceDockerX="15.0" flowable:sourceDockerY="15.0" flowable:targetDockerX="50.0" flowable:targetDockerY="40.0">
        <omgdi:waypoint x="348.44853390329115" y="164.78775666509335"></omgdi:waypoint>
        <omgdi:waypoint x="495.49999999999903" y="162.7068396226415"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-4F4853C5-0FE6-48AB-BD80-A37CF807D90D" id="BPMNEdge_sid-4F4853C5-0FE6-48AB-BD80-A37CF807D90D" flowable:sourceDockerX="50.0" flowable:sourceDockerY="40.0" flowable:targetDockerX="14.0" flowable:targetDockerY="14.0">
        <omgdi:waypoint x="595.4499999999996" y="162.94542586750788"></omgdi:waypoint>
        <omgdi:waypoint x="690.0016973189436" y="164.73506227304313"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-FBD95BC3-BA38-4863-95E6-E7D484FE80CB" id="BPMNEdge_sid-FBD95BC3-BA38-4863-95E6-E7D484FE80CB" flowable:sourceDockerX="15.0" flowable:sourceDockerY="15.0" flowable:targetDockerX="15.0" flowable:targetDockerY="15.0">
        <omgdi:waypoint x="149.94999953609073" y="165.0"></omgdi:waypoint>
        <omgdi:waypoint x="318.5" y="165.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>

先部署:

    /**
     * Deploy
     */
    @Test
    void testDeploy() throws Exception {
        //RepositoryService repositoryService = processEngine.getRepositoryService();
        Deployment deploy = repositoryService.createDeployment()
                .addClasspathResource("信号中间捕获事件.bpmn20.xml")
                .name("信号中间捕获事件")
                .deploy();
        System.out.println("deploy.getId() = " + deploy.getId());
        System.out.println("deploy.getName() = " + deploy.getName());
        System.out.println("部署开始的时间:" + new Date());
        //TimeUnit.MINUTES.sleep(3);
    }

然后我们需要启动流程:

    @Test
    void startFlow() throws Exception{
        runtimeService.startProcessInstanceById("event2002:1:adc5b8f8-afcf-11ec-959a-c03c59ad2248");
        System.out.println("启动时间:" + new Date());
    }

发送信号信息

    /**
     * 通过信号发送来触发信号启动事件的执行
     * 全局的信息
     */
    @Test
    void signalGolbal() throws Exception {
        runtimeService.signalEventReceived("secondSingal");
        // 我们得保证容器的运行,所以需要阻塞
        TimeUnit.MINUTES.sleep(1);
    }

然后被我们的信号捕获中间事件捕获

在这里插入图片描述

信号作用域为processInstance的情况

在这里插入图片描述

首先针对processInstance的信号,我们发送global信号是不会被捕获的

在这里插入图片描述

然后processInstance的信息我们需要在流程实例内部抛出信号
在这里插入图片描述

3.中间抛出事件

  信号中间抛出事件也就是在流程执行中的某个节点抛出了对应的信号,然后对应的信号中间捕获事件就会触发,我们通过具体的案例来演示如:

在这里插入图片描述

定义信息信息:

在这里插入图片描述

在这里插入图片描述

完整的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" exporter="Flowable Open Source Modeler" exporterVersion="6.7.2">
  <signal id="signal01" name="signal01" flowable:scope="global"></signal>
  <process id="event2003" name="信号中间抛出事件" isExecutable="true">
    <startEvent id="startId01" flowable:formFieldValidation="true"></startEvent>
    <parallelGateway id="pid01" name="并行网关"></parallelGateway>
    <sequenceFlow id="sid-296CDB16-A9D3-4255-9E44-D7C6F5DA5058" sourceRef="startId01" targetRef="pid01"></sequenceFlow>
    <serviceTask id="task01" name="自动任务一" flowable:class="com.bobo.delegate.MyOneDelegate"></serviceTask>
    <serviceTask id="task02" name="自动任务二" flowable:class="com.bobo.delegate.MyTwoDelegate"></serviceTask>
    <serviceTask id="task03" name="自动任务三" flowable:class="com.bobo.delegate.MyThreeDelegate"></serviceTask>
    <sequenceFlow id="sid-2325ED54-C769-4161-A00F-001F006B72B5" sourceRef="pid01" targetRef="task01"></sequenceFlow>
    <intermediateThrowEvent id="sid-262D1C04-299C-4DE6-BAD9-B8AA0FC4EBAB">
      <signalEventDefinition signalRef="signal01"></signalEventDefinition>
    </intermediateThrowEvent>
    <intermediateCatchEvent id="sid-51D70059-8D15-4BF7-9151-48CCD99544F1">
      <signalEventDefinition signalRef="signal01"></signalEventDefinition>
    </intermediateCatchEvent>
    <sequenceFlow id="sid-4A038E06-A731-4A5F-A929-840FB8A92AA5" sourceRef="task01" targetRef="sid-262D1C04-299C-4DE6-BAD9-B8AA0FC4EBAB"></sequenceFlow>
    <sequenceFlow id="sid-1C87EF67-D60F-47A3-A5B4-06FBC6F2390D" sourceRef="sid-262D1C04-299C-4DE6-BAD9-B8AA0FC4EBAB" targetRef="task02"></sequenceFlow>
    <sequenceFlow id="sid-DAC2B128-B6A7-48A2-8010-8AC6A806C04D" sourceRef="pid01" targetRef="sid-51D70059-8D15-4BF7-9151-48CCD99544F1"></sequenceFlow>
    <sequenceFlow id="sid-0ABE23AE-344C-49D8-B574-010DECD093BE" sourceRef="sid-51D70059-8D15-4BF7-9151-48CCD99544F1" targetRef="task03"></sequenceFlow>
    <parallelGateway id="pid02" name="并行网关"></parallelGateway>
    <sequenceFlow id="sid-584ADF4E-9140-4E5A-A396-1257E1436704" sourceRef="task02" targetRef="pid02"></sequenceFlow>
    <sequenceFlow id="sid-857F5F7F-7EA9-4986-9270-FFBF13E0B8CD" sourceRef="task03" targetRef="pid02"></sequenceFlow>
    <endEvent id="end01" name="结束"></endEvent>
    <sequenceFlow id="sid-02646A89-FCEC-4E7F-95B8-61F2065DE8D4" sourceRef="pid02" targetRef="end01"></sequenceFlow>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_event2003">
    <bpmndi:BPMNPlane bpmnElement="event2003" id="BPMNPlane_event2003">
      <bpmndi:BPMNShape bpmnElement="startId01" id="BPMNShape_startId01">
        <omgdc:Bounds height="30.0" width="30.0" x="100.0" y="163.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="pid01" id="BPMNShape_pid01">
        <omgdc:Bounds height="40.0" width="40.0" x="270.0" y="158.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="task01" id="BPMNShape_task01">
        <omgdc:Bounds height="80.0" width="100.0" x="419.5" y="71.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="task02" id="BPMNShape_task02">
        <omgdc:Bounds height="80.0" width="100.0" x="780.0" y="71.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="task03" id="BPMNShape_task03">
        <omgdc:Bounds height="80.0" width="100.0" x="795.0" y="255.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-262D1C04-299C-4DE6-BAD9-B8AA0FC4EBAB" id="BPMNShape_sid-262D1C04-299C-4DE6-BAD9-B8AA0FC4EBAB">
        <omgdc:Bounds height="30.0" width="30.0" x="633.5" y="96.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-51D70059-8D15-4BF7-9151-48CCD99544F1" id="BPMNShape_sid-51D70059-8D15-4BF7-9151-48CCD99544F1">
        <omgdc:Bounds height="30.0" width="30.0" x="465.0" y="278.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="pid02" id="BPMNShape_pid02">
        <omgdc:Bounds height="40.0" width="40.0" x="994.5" y="158.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="end01" id="BPMNShape_end01">
        <omgdc:Bounds height="28.0" width="28.0" x="1079.5" y="164.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="sid-4A038E06-A731-4A5F-A929-840FB8A92AA5" id="BPMNEdge_sid-4A038E06-A731-4A5F-A929-840FB8A92AA5" flowable:sourceDockerX="50.0" flowable:sourceDockerY="40.0" flowable:targetDockerX="15.0" flowable:targetDockerY="15.0">
        <omgdi:waypoint x="519.45" y="111.0"></omgdi:waypoint>
        <omgdi:waypoint x="633.5" y="111.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-02646A89-FCEC-4E7F-95B8-61F2065DE8D4" id="BPMNEdge_sid-02646A89-FCEC-4E7F-95B8-61F2065DE8D4" flowable:sourceDockerX="20.5" flowable:sourceDockerY="20.5" flowable:targetDockerX="14.0" flowable:targetDockerY="14.0">
        <omgdi:waypoint x="1034.0591869398208" y="178.3782051282051"></omgdi:waypoint>
        <omgdi:waypoint x="1079.5002755524838" y="178.08885188426407"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-857F5F7F-7EA9-4986-9270-FFBF13E0B8CD" id="BPMNEdge_sid-857F5F7F-7EA9-4986-9270-FFBF13E0B8CD" flowable:sourceDockerX="50.0" flowable:sourceDockerY="40.0" flowable:targetDockerX="20.0" flowable:targetDockerY="20.0">
        <omgdi:waypoint x="894.9499999999999" y="260.4867256637168"></omgdi:waypoint>
        <omgdi:waypoint x="1002.6675392670157" y="186.14712041884815"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-1C87EF67-D60F-47A3-A5B4-06FBC6F2390D" id="BPMNEdge_sid-1C87EF67-D60F-47A3-A5B4-06FBC6F2390D" flowable:sourceDockerX="15.0" flowable:sourceDockerY="15.0" flowable:targetDockerX="50.0" flowable:targetDockerY="40.0">
        <omgdi:waypoint x="663.4499994451444" y="111.0"></omgdi:waypoint>
        <omgdi:waypoint x="779.9999999999972" y="111.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-0ABE23AE-344C-49D8-B574-010DECD093BE" id="BPMNEdge_sid-0ABE23AE-344C-49D8-B574-010DECD093BE" flowable:sourceDockerX="15.0" flowable:sourceDockerY="15.0" flowable:targetDockerX="50.0" flowable:targetDockerY="40.0">
        <omgdi:waypoint x="494.9497692355611" y="293.0819166248564"></omgdi:waypoint>
        <omgdi:waypoint x="794.9999999999911" y="294.7260273972602"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-584ADF4E-9140-4E5A-A396-1257E1436704" id="BPMNEdge_sid-584ADF4E-9140-4E5A-A396-1257E1436704" flowable:sourceDockerX="50.0" flowable:sourceDockerY="40.0" flowable:targetDockerX="20.0" flowable:targetDockerY="20.0">
        <omgdi:waypoint x="879.9499999999999" y="129.1390243902439"></omgdi:waypoint>
        <omgdi:waypoint x="999.8065381558029" y="172.67196819085487"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-2325ED54-C769-4161-A00F-001F006B72B5" id="BPMNEdge_sid-2325ED54-C769-4161-A00F-001F006B72B5" flowable:sourceDockerX="20.5" flowable:sourceDockerY="20.5" flowable:targetDockerX="50.0" flowable:targetDockerY="40.0">
        <omgdi:waypoint x="304.9870182555781" y="173.0233265720081"></omgdi:waypoint>
        <omgdi:waypoint x="419.49999999999994" y="129.8358938547486"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-DAC2B128-B6A7-48A2-8010-8AC6A806C04D" id="BPMNEdge_sid-DAC2B128-B6A7-48A2-8010-8AC6A806C04D" flowable:sourceDockerX="20.5" flowable:sourceDockerY="20.5" flowable:targetDockerX="15.0" flowable:targetDockerY="15.0">
        <omgdi:waypoint x="302.31181354817494" y="185.6374177631579"></omgdi:waypoint>
        <omgdi:waypoint x="467.15151373509184" y="285.24160328636844"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-296CDB16-A9D3-4255-9E44-D7C6F5DA5058" id="BPMNEdge_sid-296CDB16-A9D3-4255-9E44-D7C6F5DA5058" flowable:sourceDockerX="15.0" flowable:sourceDockerY="15.0" flowable:targetDockerX="20.0" flowable:targetDockerY="20.0">
        <omgdi:waypoint x="129.94999940317362" y="178.0"></omgdi:waypoint>
        <omgdi:waypoint x="270.0" y="178.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>

三个自定义任务绑定了三个javaDelegate分别给出打印语句来记录

然后部署任务

    @Test
    public void test02() throws Exception{

        Deployment deployment = processEngine.getRepositoryService().createDeployment()
                .addClasspathResource("信号中间抛出事件.bpmn20.xml")
                .name("信号中间抛出事件")
                .deploy();
        System.out.println("-----");
    }

然后在启动任务即可

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

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

看控制台的输出

在这里插入图片描述

效果:

在这里插入图片描述

4. 边界事件

  最后来看看信号边界事件,案例如下:

在这里插入图片描述

完整的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" exporter="Flowable Open Source Modeler" exporterVersion="6.7.2">
  <signal id="signal2" name="signal2" flowable:scope="global"></signal>
  <process id="event2004" name="信号边界事件" isExecutable="true">
    <startEvent id="startEvent1" flowable:formFieldValidation="true"></startEvent>
    <userTask id="sid-F11058BE-828A-45FF-A830-8BF099D71FBD" name="人工任务" flowable:assignee="zhangsan" flowable:formFieldValidation="true">
      <extensionElements>
        <modeler:initiator-can-complete xmlns:modeler="http://flowable.org/modeler"><![CDATA[false]]></modeler:initiator-can-complete>
      </extensionElements>
    </userTask>
    <sequenceFlow id="sid-D2EE279A-24A2-4B6C-8021-ADC0A1A645EC" sourceRef="startEvent1" targetRef="sid-F11058BE-828A-45FF-A830-8BF099D71FBD"></sequenceFlow>
    <serviceTask id="sid-FAB46591-3247-4776-B3B5-79826133F5AF" name="自动任务一" flowable:class="com.bobo.delegate.MyOneDelegate"></serviceTask>
    <serviceTask id="sid-7CD0FBBA-4FE6-4646-B0D6-1D8A4D8D5515" name="自动任务二" flowable:class="com.bobo.delegate.MyTwoDelegate"></serviceTask>
    <sequenceFlow id="sid-74B48035-4CED-4963-AA87-55D1FB95EEA8" sourceRef="sid-F11058BE-828A-45FF-A830-8BF099D71FBD" targetRef="sid-FAB46591-3247-4776-B3B5-79826133F5AF"></sequenceFlow>
    <endEvent id="sid-55682CDC-FEBD-44A1-B38C-A3F816AC91F4"></endEvent>
    <sequenceFlow id="sid-AC84425B-8D8C-4A0F-BDCC-BC1DCF909752" sourceRef="sid-FAB46591-3247-4776-B3B5-79826133F5AF" targetRef="sid-55682CDC-FEBD-44A1-B38C-A3F816AC91F4"></sequenceFlow>
    <endEvent id="sid-11CA784C-69DE-45B2-AE58-78E64CF2EE8E"></endEvent>
    <sequenceFlow id="sid-A2E3E7C7-9AD0-46B8-8105-272496599E0D" sourceRef="sid-7CD0FBBA-4FE6-4646-B0D6-1D8A4D8D5515" targetRef="sid-11CA784C-69DE-45B2-AE58-78E64CF2EE8E"></sequenceFlow>
    <boundaryEvent id="sid-8E473D8E-70D6-4AB3-B1D9-D3E7EFCDB39D" attachedToRef="sid-F11058BE-828A-45FF-A830-8BF099D71FBD" cancelActivity="true">
      <signalEventDefinition signalRef="signal2"></signalEventDefinition>
    </boundaryEvent>
    <sequenceFlow id="sid-C3770DF2-1747-45A7-85B5-2838AB7ECF9C" sourceRef="sid-8E473D8E-70D6-4AB3-B1D9-D3E7EFCDB39D" targetRef="sid-7CD0FBBA-4FE6-4646-B0D6-1D8A4D8D5515"></sequenceFlow>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_event2004">
    <bpmndi:BPMNPlane bpmnElement="event2004" id="BPMNPlane_event2004">
      <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-F11058BE-828A-45FF-A830-8BF099D71FBD" id="BPMNShape_sid-F11058BE-828A-45FF-A830-8BF099D71FBD">
        <omgdc:Bounds height="80.0" width="100.0" x="255.0" y="138.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-FAB46591-3247-4776-B3B5-79826133F5AF" id="BPMNShape_sid-FAB46591-3247-4776-B3B5-79826133F5AF">
        <omgdc:Bounds height="80.0" width="100.0" x="521.5" y="135.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-7CD0FBBA-4FE6-4646-B0D6-1D8A4D8D5515" id="BPMNShape_sid-7CD0FBBA-4FE6-4646-B0D6-1D8A4D8D5515">
        <omgdc:Bounds height="80.0" width="100.0" x="521.5" y="315.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-55682CDC-FEBD-44A1-B38C-A3F816AC91F4" id="BPMNShape_sid-55682CDC-FEBD-44A1-B38C-A3F816AC91F4">
        <omgdc:Bounds height="28.0" width="28.0" x="690.0" y="161.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-11CA784C-69DE-45B2-AE58-78E64CF2EE8E" id="BPMNShape_sid-11CA784C-69DE-45B2-AE58-78E64CF2EE8E">
        <omgdc:Bounds height="28.0" width="28.0" x="690.0" y="341.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-8E473D8E-70D6-4AB3-B1D9-D3E7EFCDB39D" id="BPMNShape_sid-8E473D8E-70D6-4AB3-B1D9-D3E7EFCDB39D">
        <omgdc:Bounds height="30.0" width="30.0" x="308.4527694396093" y="203.7233532460343"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="sid-C3770DF2-1747-45A7-85B5-2838AB7ECF9C" id="BPMNEdge_sid-C3770DF2-1747-45A7-85B5-2838AB7ECF9C" flowable:sourceDockerX="15.0" flowable:sourceDockerY="15.0" flowable:targetDockerX="50.0" flowable:targetDockerY="40.0">
        <omgdi:waypoint x="336.557461183174" y="225.9233207922021"></omgdi:waypoint>
        <omgdi:waypoint x="521.4999999999999" y="327.5301011331414"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-74B48035-4CED-4963-AA87-55D1FB95EEA8" id="BPMNEdge_sid-74B48035-4CED-4963-AA87-55D1FB95EEA8" flowable:sourceDockerX="50.0" flowable:sourceDockerY="40.0" flowable:targetDockerX="50.0" flowable:targetDockerY="40.0">
        <omgdi:waypoint x="354.95000000000005" y="177.43714821763604"></omgdi:waypoint>
        <omgdi:waypoint x="521.5" y="175.56228893058162"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-D2EE279A-24A2-4B6C-8021-ADC0A1A645EC" id="BPMNEdge_sid-D2EE279A-24A2-4B6C-8021-ADC0A1A645EC" flowable:sourceDockerX="15.0" flowable:sourceDockerY="15.0" flowable:targetDockerX="50.0" flowable:targetDockerY="40.0">
        <omgdi:waypoint x="129.94999949366624" y="178.0"></omgdi:waypoint>
        <omgdi:waypoint x="254.99999999993574" y="178.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-A2E3E7C7-9AD0-46B8-8105-272496599E0D" id="BPMNEdge_sid-A2E3E7C7-9AD0-46B8-8105-272496599E0D" flowable:sourceDockerX="50.0" flowable:sourceDockerY="40.0" flowable:targetDockerX="14.0" flowable:targetDockerY="14.0">
        <omgdi:waypoint x="621.4499999999999" y="355.0"></omgdi:waypoint>
        <omgdi:waypoint x="690.0" y="355.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-AC84425B-8D8C-4A0F-BDCC-BC1DCF909752" id="BPMNEdge_sid-AC84425B-8D8C-4A0F-BDCC-BC1DCF909752" flowable:sourceDockerX="50.0" flowable:sourceDockerY="40.0" flowable:targetDockerX="14.0" flowable:targetDockerY="14.0">
        <omgdi:waypoint x="621.4499999999999" y="175.0"></omgdi:waypoint>
        <omgdi:waypoint x="690.0" y="175.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>

定义的信号为:

<signal id="signal2" name="signal2" flowable:scope="global"></signal>

自动任务的内容

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

        System.out.println("完成自动审批任务-----》MyOneDelegate" + LocalDateTime.now().toString());
    }
}

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

部署项目然后启动流程

    @Test
    public void test02() throws Exception{

        Deployment deployment = processEngine.getRepositoryService().createDeployment()
                .addClasspathResource("信号边界事件.bpmn20.xml")
                .name("信号边界事件")
                .deploy();
        System.out.println("-----");
    }

    @Test
    public void startProcessInstanceByKey()  throws Exception{

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

在这里插入图片描述

    @Test
    public void signalGlobal()  throws Exception{
        String signal = "signal2";
        Map<String, Object> variables = new HashMap();
        processEngine.getRuntimeService().signalEventReceived(signal,variables);
    }

在这里插入图片描述

通过输出看到了我们期望的结果了,这样就给大家介绍完了信号相关的各种事件了

文章来源: dpb-bobokaoya-sm.blog.csdn.net,作者:波波烤鸭,版权归原作者所有,如需转载,请联系作者。

原文链接:dpb-bobokaoya-sm.blog.csdn.net/article/details/124057246

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。