[图片] 网关 网关被用来控制流程走向。它能够生成或消费令牌。 网关类型包括: 排它网关 并行网关 包容网关 事件网关 1. 排它网关 当执行到达此网关时,将按照定义它们的顺序评估所有传出顺序流。 选择条件评估为真的序列流以继续该过程。 如果多个序列流具有计算结果为 true,则选择 XML 中定义的第一个, 如果不能 ..

Gateways of Activiti 6.x

本贴最后更新于 184 天前,其中的信息可能已经天翻地覆

网关

网关被用来控制流程走向。它能够生成或消费令牌。

网关类型包括:

1. 排它网关

当执行到达此网关时,将按照定义它们的顺序评估所有传出顺序流。 选择条件评估为真的序列流以继续该过程。 如果多个序列流具有计算结果为 true,则选择 XML 中定义的第一个, 如果不能选择序列流,则会抛出异常。

流程图:
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="ExclusiveGatewayProcess_1" name="排它网关" isExecutable="true">
    <startEvent id="startEvent1"></startEvent>
    <exclusiveGateway id="sid-92D036D3-558F-4DC5-8099-5E7F265129F9"></exclusiveGateway>
    <sequenceFlow id="sid-925FBF47-AEC7-4393-B290-FDE6686E8D95" sourceRef="startEvent1" targetRef="sid-92D036D3-558F-4DC5-8099-5E7F265129F9"></sequenceFlow>
    <endEvent id="sid-C6DB6D23-9C0E-4751-AC32-DB8C225EFA03">
      <extensionElements>
        <activiti:executionListener event="end" expression="#{exclusiveGatewayExecutionListener.firstEnd(execution)}"></activiti:executionListener>
      </extensionElements>
    </endEvent>
    <endEvent id="sid-B7986E34-65BB-4398-9271-B975B49EFD63">
      <extensionElements>
        <activiti:executionListener event="end" expression="#{exclusiveGatewayExecutionListener.secondEnd(execution)}"></activiti:executionListener>
      </extensionElements>
    </endEvent>
    <endEvent id="sid-BDA38006-2CEC-4D85-B4F8-152FBDC5885C">
      <extensionElements>
        <activiti:executionListener event="end" expression="#{exclusiveGatewayExecutionListener.thirdEnd(execution)}"></activiti:executionListener>
      </extensionElements>
    </endEvent>
    <sequenceFlow id="sid-93F82AFF-FCFA-4D40-A9A0-66A50A0CBC89" sourceRef="sid-92D036D3-558F-4DC5-8099-5E7F265129F9" targetRef="sid-BDA38006-2CEC-4D85-B4F8-152FBDC5885C">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${f%3==2}]]></conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="sid-044A6E1B-6410-477E-907C-DEC19CF0525D" sourceRef="sid-92D036D3-558F-4DC5-8099-5E7F265129F9" targetRef="sid-B7986E34-65BB-4398-9271-B975B49EFD63">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${f%3==1}]]></conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="sid-306FB86E-AC9F-4BEA-82D9-AE4A8C107995" sourceRef="sid-92D036D3-558F-4DC5-8099-5E7F265129F9" targetRef="sid-C6DB6D23-9C0E-4751-AC32-DB8C225EFA03">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${f%3==0}]]></conditionExpression>
    </sequenceFlow>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_ExclusiveGatewayProcess_1">
    <bpmndi:BPMNPlane bpmnElement="ExclusiveGatewayProcess_1" id="BPMNPlane_ExclusiveGatewayProcess_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-92D036D3-558F-4DC5-8099-5E7F265129F9" id="BPMNShape_sid-92D036D3-558F-4DC5-8099-5E7F265129F9">
        <omgdc:Bounds height="40.0" width="40.0" x="165.0" y="175.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-C6DB6D23-9C0E-4751-AC32-DB8C225EFA03" id="BPMNShape_sid-C6DB6D23-9C0E-4751-AC32-DB8C225EFA03">
        <omgdc:Bounds height="28.0" width="28.0" x="270.0" y="90.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-B7986E34-65BB-4398-9271-B975B49EFD63" id="BPMNShape_sid-B7986E34-65BB-4398-9271-B975B49EFD63">
        <omgdc:Bounds height="28.0" width="28.0" x="270.0" y="181.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-BDA38006-2CEC-4D85-B4F8-152FBDC5885C" id="BPMNShape_sid-BDA38006-2CEC-4D85-B4F8-152FBDC5885C">
        <omgdc:Bounds height="28.0" width="28.0" x="270.0" y="315.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="sid-93F82AFF-FCFA-4D40-A9A0-66A50A0CBC89" id="BPMNEdge_sid-93F82AFF-FCFA-4D40-A9A0-66A50A0CBC89">
        <omgdi:waypoint x="185.5" y="214.5"></omgdi:waypoint>
        <omgdi:waypoint x="185.5" y="329.0"></omgdi:waypoint>
        <omgdi:waypoint x="270.0" y="329.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-306FB86E-AC9F-4BEA-82D9-AE4A8C107995" id="BPMNEdge_sid-306FB86E-AC9F-4BEA-82D9-AE4A8C107995">
        <omgdi:waypoint x="185.5" y="175.5"></omgdi:waypoint>
        <omgdi:waypoint x="185.5" y="104.0"></omgdi:waypoint>
        <omgdi:waypoint x="270.0" y="104.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-044A6E1B-6410-477E-907C-DEC19CF0525D" id="BPMNEdge_sid-044A6E1B-6410-477E-907C-DEC19CF0525D">
        <omgdi:waypoint x="204.5969387755102" y="195.4030612244898"></omgdi:waypoint>
        <omgdi:waypoint x="270.00018036704694" y="195.07106507427895"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-925FBF47-AEC7-4393-B290-FDE6686E8D95" id="BPMNEdge_sid-925FBF47-AEC7-4393-B290-FDE6686E8D95">
        <omgdi:waypoint x="119.99971066768252" y="195.0931659047682"></omgdi:waypoint>
        <omgdi:waypoint x="165.375" y="195.375"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>

2. 并行网关

并行网关的功能基于传入和传出顺序流。
fork:并行执行所有传出序列流,为每个序列流创建一个并发执行。
image.png

join:到达并行网关的所有并发执行在网关中等待,直到每个传入的序列流都到达执行,然后流程通过加入网关。
Note:并行网关不需要设置条件表达式,即使有,也是会被忽略的。
image.png

流程图:
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="ParallelGatewayProcess_1" name="并行网关" isExecutable="true">
    <startEvent id="startEvent1"></startEvent>
    <sequenceFlow id="sid-9AEA4400-D584-4B4C-ACEF-924AC2B591BF" sourceRef="startEvent1" targetRef="sid-BD9528CF-96EC-4C44-A29C-86C1B90C2E56"></sequenceFlow>
    <parallelGateway id="sid-BD9528CF-96EC-4C44-A29C-86C1B90C2E56"></parallelGateway>
    <parallelGateway id="sid-2136838E-624D-4443-B521-5C639809F1A0"></parallelGateway>
    <endEvent id="sid-256D56E9-8A20-4570-B0A9-5372750B3F09">
      <extensionElements>
        <activiti:executionListener event="end" expression="#{parallelGatewayExecutionListener.parallelEnd(execution)}"></activiti:executionListener>
      </extensionElements>
    </endEvent>
    <sequenceFlow id="sid-75DFAAF0-F6C8-49D8-8254-14F091378741" sourceRef="sid-2136838E-624D-4443-B521-5C639809F1A0" targetRef="sid-256D56E9-8A20-4570-B0A9-5372750B3F09"></sequenceFlow>
    <intermediateThrowEvent id="sid-B70FDA5E-2965-4494-9A54-2DF425D26836">
      <extensionElements>
        <activiti:executionListener event="end" expression="#{parallelGatewayExecutionListener.parallelSecondPass(execution)}"></activiti:executionListener>
      </extensionElements>
    </intermediateThrowEvent>
    <intermediateThrowEvent id="sid-0D8EBBF5-6956-42CE-A1DA-0FA72CA519AB">
      <extensionElements>
        <activiti:executionListener event="end" expression="#{parallelGatewayExecutionListener.parallelFirstPass(execution)}"></activiti:executionListener>
      </extensionElements>
    </intermediateThrowEvent>
    <sequenceFlow id="sid-3ED22E37-BD9D-4D66-AC69-4FA092390EC2" sourceRef="sid-0D8EBBF5-6956-42CE-A1DA-0FA72CA519AB" targetRef="sid-2136838E-624D-4443-B521-5C639809F1A0"></sequenceFlow>
    <sequenceFlow id="sid-8DF8CF58-644C-4F42-9370-87B402CDBCDD" sourceRef="sid-B70FDA5E-2965-4494-9A54-2DF425D26836" targetRef="sid-2136838E-624D-4443-B521-5C639809F1A0"></sequenceFlow>
    <sequenceFlow id="sid-90A4771F-3C72-453F-8293-4D45CDC6A9A5" sourceRef="sid-BD9528CF-96EC-4C44-A29C-86C1B90C2E56" targetRef="sid-0D8EBBF5-6956-42CE-A1DA-0FA72CA519AB"></sequenceFlow>
    <sequenceFlow id="sid-6D19DF5E-9C19-4A6B-875F-DB89EF86DEFE" sourceRef="sid-BD9528CF-96EC-4C44-A29C-86C1B90C2E56" targetRef="sid-B70FDA5E-2965-4494-9A54-2DF425D26836"></sequenceFlow>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_ParallelGatewayProcess_1">
    <bpmndi:BPMNPlane bpmnElement="ParallelGatewayProcess_1" id="BPMNPlane_ParallelGatewayProcess_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-BD9528CF-96EC-4C44-A29C-86C1B90C2E56" id="BPMNShape_sid-BD9528CF-96EC-4C44-A29C-86C1B90C2E56">
        <omgdc:Bounds height="40.0" width="40.0" x="175.0" y="158.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-2136838E-624D-4443-B521-5C639809F1A0" id="BPMNShape_sid-2136838E-624D-4443-B521-5C639809F1A0">
        <omgdc:Bounds height="40.0" width="40.0" x="525.0" y="158.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-256D56E9-8A20-4570-B0A9-5372750B3F09" id="BPMNShape_sid-256D56E9-8A20-4570-B0A9-5372750B3F09">
        <omgdc:Bounds height="28.0" width="28.0" x="610.0" y="164.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-B70FDA5E-2965-4494-9A54-2DF425D26836" id="BPMNShape_sid-B70FDA5E-2965-4494-9A54-2DF425D26836">
        <omgdc:Bounds height="30.0" width="30.0" x="305.0" y="270.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-0D8EBBF5-6956-42CE-A1DA-0FA72CA519AB" id="BPMNShape_sid-0D8EBBF5-6956-42CE-A1DA-0FA72CA519AB">
        <omgdc:Bounds height="30.0" width="30.0" x="305.0" y="75.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="sid-9AEA4400-D584-4B4C-ACEF-924AC2B591BF" id="BPMNEdge_sid-9AEA4400-D584-4B4C-ACEF-924AC2B591BF">
        <omgdi:waypoint x="129.9997106676825" y="178.0931659047682"></omgdi:waypoint>
        <omgdi:waypoint x="175.375" y="178.375"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-3ED22E37-BD9D-4D66-AC69-4FA092390EC2" id="BPMNEdge_sid-3ED22E37-BD9D-4D66-AC69-4FA092390EC2">
        <omgdi:waypoint x="335.0" y="90.0"></omgdi:waypoint>
        <omgdi:waypoint x="545.5" y="90.0"></omgdi:waypoint>
        <omgdi:waypoint x="545.5" y="158.5"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-6D19DF5E-9C19-4A6B-875F-DB89EF86DEFE" id="BPMNEdge_sid-6D19DF5E-9C19-4A6B-875F-DB89EF86DEFE">
        <omgdi:waypoint x="195.5" y="197.5"></omgdi:waypoint>
        <omgdi:waypoint x="195.5" y="285.0"></omgdi:waypoint>
        <omgdi:waypoint x="305.0" y="285.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-90A4771F-3C72-453F-8293-4D45CDC6A9A5" id="BPMNEdge_sid-90A4771F-3C72-453F-8293-4D45CDC6A9A5">
        <omgdi:waypoint x="195.5" y="158.5"></omgdi:waypoint>
        <omgdi:waypoint x="195.5" y="90.0"></omgdi:waypoint>
        <omgdi:waypoint x="305.0" y="90.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-75DFAAF0-F6C8-49D8-8254-14F091378741" id="BPMNEdge_sid-75DFAAF0-F6C8-49D8-8254-14F091378741">
        <omgdi:waypoint x="564.6217948717949" y="178.37820512820514"></omgdi:waypoint>
        <omgdi:waypoint x="610.0002839785394" y="178.0891701657418"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-8DF8CF58-644C-4F42-9370-87B402CDBCDD" id="BPMNEdge_sid-8DF8CF58-644C-4F42-9370-87B402CDBCDD">
        <omgdi:waypoint x="335.0" y="285.0"></omgdi:waypoint>
        <omgdi:waypoint x="545.5" y="285.0"></omgdi:waypoint>
        <omgdi:waypoint x="545.5" y="197.5"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>

3. 包容网关

包容网关的功能基于传入和传出顺序流。
fork:评估所有传出序列流条件,并且对于评估为 true 的序列流条件,并行地遵循流,为每个序列流创建一个并发执行。

join:到达包容网关的所有并发执行在网关中等待,直到具有进程令牌的传入序列流到达执行。这是与并行网关的重要区别。换句话说,包容性网关将只等待将要执行的传入序列流。在加入之后,该过程继续通过包容网关。

流程图:
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="InclusiveGatewayProcess_1" name="包容网关" isExecutable="true">
    <startEvent id="startEvent1"></startEvent>
    <sequenceFlow id="sid-201A68B9-8B71-4171-A45B-4FF9A7068F51" sourceRef="startEvent1" targetRef="sid-3B13ED63-7A6E-41BB-A611-F86E6730C7B8"></sequenceFlow>
    <inclusiveGateway id="sid-3B13ED63-7A6E-41BB-A611-F86E6730C7B8"></inclusiveGateway>
    <intermediateThrowEvent id="sid-8668FD9E-771C-4078-B33F-265EB13476FE">
      <extensionElements>
        <activiti:executionListener event="end" expression="#{inclusiveGatewayExecutionListener.inclusiveFirstPass(execution)}"></activiti:executionListener>
      </extensionElements>
    </intermediateThrowEvent>
    <intermediateThrowEvent id="sid-D98D059C-F490-4475-8DA8-662D282EDBEB">
      <extensionElements>
        <activiti:executionListener event="end" expression="#{inclusiveGatewayExecutionListener.inclusiveSecondPass(execution)}"></activiti:executionListener>
      </extensionElements>
    </intermediateThrowEvent>
    <inclusiveGateway id="sid-26DF8717-130F-43C2-B53A-6B9E21C1DD5A"></inclusiveGateway>
    <endEvent id="sid-B4BB717C-391D-4F88-91DF-890CEE651B92">
      <extensionElements>
        <activiti:executionListener event="end" expression="#{inclusiveGatewayExecutionListener.inclusiveEnd(execution)}"></activiti:executionListener>
      </extensionElements>
    </endEvent>
    <sequenceFlow id="sid-B0B16522-A71D-4BD0-9C5B-A32F805176F2" sourceRef="sid-26DF8717-130F-43C2-B53A-6B9E21C1DD5A" targetRef="sid-B4BB717C-391D-4F88-91DF-890CEE651B92"></sequenceFlow>
    <sequenceFlow id="sid-F608EBF6-8145-4FAD-8627-575E21CE097C" sourceRef="sid-3B13ED63-7A6E-41BB-A611-F86E6730C7B8" targetRef="sid-D98D059C-F490-4475-8DA8-662D282EDBEB">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${f%2==1}]]></conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="sid-F5E748AB-CBB2-4580-9F12-CD7A0F28BD8A" sourceRef="sid-3B13ED63-7A6E-41BB-A611-F86E6730C7B8" targetRef="sid-8668FD9E-771C-4078-B33F-265EB13476FE">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${f%2==0}]]></conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="sid-DC97AA77-A07A-458D-93D2-1C47EDAD316F" sourceRef="sid-8668FD9E-771C-4078-B33F-265EB13476FE" targetRef="sid-26DF8717-130F-43C2-B53A-6B9E21C1DD5A">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[#{f==0}]]></conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="sid-775F909E-88ED-4954-9B42-6C9D3714C0A4" sourceRef="sid-D98D059C-F490-4475-8DA8-662D282EDBEB" targetRef="sid-26DF8717-130F-43C2-B53A-6B9E21C1DD5A">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[#{f==1}]]></conditionExpression>
    </sequenceFlow>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_InclusiveGatewayProcess_1">
    <bpmndi:BPMNPlane bpmnElement="InclusiveGatewayProcess_1" id="BPMNPlane_InclusiveGatewayProcess_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-3B13ED63-7A6E-41BB-A611-F86E6730C7B8" id="BPMNShape_sid-3B13ED63-7A6E-41BB-A611-F86E6730C7B8">
        <omgdc:Bounds height="40.0" width="40.0" x="175.0" y="158.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-8668FD9E-771C-4078-B33F-265EB13476FE" id="BPMNShape_sid-8668FD9E-771C-4078-B33F-265EB13476FE">
        <omgdc:Bounds height="30.0" width="30.0" x="300.0" y="84.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-D98D059C-F490-4475-8DA8-662D282EDBEB" id="BPMNShape_sid-D98D059C-F490-4475-8DA8-662D282EDBEB">
        <omgdc:Bounds height="30.0" width="30.0" x="300.0" y="240.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-26DF8717-130F-43C2-B53A-6B9E21C1DD5A" id="BPMNShape_sid-26DF8717-130F-43C2-B53A-6B9E21C1DD5A">
        <omgdc:Bounds height="40.0" width="40.0" x="450.0" y="158.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-B4BB717C-391D-4F88-91DF-890CEE651B92" id="BPMNShape_sid-B4BB717C-391D-4F88-91DF-890CEE651B92">
        <omgdc:Bounds height="28.0" width="28.0" x="535.0" y="164.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="sid-201A68B9-8B71-4171-A45B-4FF9A7068F51" id="BPMNEdge_sid-201A68B9-8B71-4171-A45B-4FF9A7068F51">
        <omgdi:waypoint x="129.9997106676825" y="178.0931659047682"></omgdi:waypoint>
        <omgdi:waypoint x="175.375" y="178.375"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-DC97AA77-A07A-458D-93D2-1C47EDAD316F" id="BPMNEdge_sid-DC97AA77-A07A-458D-93D2-1C47EDAD316F">
        <omgdi:waypoint x="328.3557466749862" y="105.82817916824055"></omgdi:waypoint>
        <omgdi:waypoint x="456.60425531914893" y="171.39574468085107"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-775F909E-88ED-4954-9B42-6C9D3714C0A4" id="BPMNEdge_sid-775F909E-88ED-4954-9B42-6C9D3714C0A4">
        <omgdi:waypoint x="328.4594064904438" y="248.3784913407141"></omgdi:waypoint>
        <omgdi:waypoint x="457.0948275862069" y="185.0948275862069"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-F608EBF6-8145-4FAD-8627-575E21CE097C" id="BPMNEdge_sid-F608EBF6-8145-4FAD-8627-575E21CE097C">
        <omgdi:waypoint x="207.0841836734694" y="185.9158163265306"></omgdi:waypoint>
        <omgdi:waypoint x="302.36688904651373" y="246.91269466157576"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-F5E748AB-CBB2-4580-9F12-CD7A0F28BD8A" id="BPMNEdge_sid-F5E748AB-CBB2-4580-9F12-CD7A0F28BD8A">
        <omgdi:waypoint x="207.51005025125627" y="170.51005025125627"></omgdi:waypoint>
        <omgdi:waypoint x="302.51121228086083" y="107.30844036545241"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-B0B16522-A71D-4BD0-9C5B-A32F805176F2" id="BPMNEdge_sid-B0B16522-A71D-4BD0-9C5B-A32F805176F2">
        <omgdi:waypoint x="489.62179487179486" y="178.37820512820514"></omgdi:waypoint>
        <omgdi:waypoint x="535.0002839785394" y="178.0891701657418"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>

4. 事件网关

事件网关允许基于事件做出决定,网关的每个输出序列流需要连接到中间捕获事件。当进程执行到事件网关时,执行被暂停,对于每个传出的序列流,为其创建事件订阅。
Note:
1. 事件网关必须具有两个或以上的传出序列流。
2. 只能连接 intermediateCatchEvent 的元素。
3. 连接事件网关的 intermediateCatchEvent 必须具有单个接入序列流。

流程图:
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="signalEventGateway" name="signalEventGateway"></signal>
  <process id="EventGatewayProcess_1" name="事件网关" isExecutable="true">
    <startEvent id="startEvent1"></startEvent>
    <eventBasedGateway id="sid-C6B0BBD0-D2C9-4F94-B547-076D6D2611AC"></eventBasedGateway>
    <intermediateCatchEvent id="sid-BF8A0064-82EE-47E9-A977-59A9B7EDBE80">
      <extensionElements>
        <activiti:executionListener event="end" expression="#{eventGatewayExecutionListener.passTimer(execution)}"></activiti:executionListener>
      </extensionElements>
      <timerEventDefinition>
        <timeDuration>PT5S</timeDuration>
      </timerEventDefinition>
    </intermediateCatchEvent>
    <exclusiveGateway id="sid-BE8A4B9D-AEA3-47BB-8576-9A95431313AD"></exclusiveGateway>
    <endEvent id="sid-1789888F-6F0D-48BF-9F3E-89C8D25DA753">
      <extensionElements>
        <activiti:executionListener event="end" expression="#{eventGatewayExecutionListener.processEnd(execution)}"></activiti:executionListener>
      </extensionElements>
    </endEvent>
    <sequenceFlow id="sid-C593234B-2FEC-4B30-A21D-C297B10FF537" sourceRef="startEvent1" targetRef="sid-C6B0BBD0-D2C9-4F94-B547-076D6D2611AC"></sequenceFlow>
    <sequenceFlow id="sid-9E68BD45-ACD2-43C0-87C7-D52F26F41F1F" sourceRef="sid-C6B0BBD0-D2C9-4F94-B547-076D6D2611AC" targetRef="sid-BF8A0064-82EE-47E9-A977-59A9B7EDBE80"></sequenceFlow>
    <sequenceFlow id="sid-C03C593D-63B0-4464-9240-1EDF44F446D4" sourceRef="sid-BE8A4B9D-AEA3-47BB-8576-9A95431313AD" targetRef="sid-1789888F-6F0D-48BF-9F3E-89C8D25DA753"></sequenceFlow>
    <sequenceFlow id="sid-66CF7079-A547-4AB0-AE4D-5E7B0FD2CAFD" sourceRef="sid-BF8A0064-82EE-47E9-A977-59A9B7EDBE80" targetRef="sid-BE8A4B9D-AEA3-47BB-8576-9A95431313AD"></sequenceFlow>
    <intermediateCatchEvent id="sid-08127570-1DFC-497B-900F-681D19FCA78B">
      <extensionElements>
        <activiti:executionListener event="end" expression="#{eventGatewayExecutionListener.passSignal(execution)}"></activiti:executionListener>
      </extensionElements>
      <signalEventDefinition signalRef="signalEventGateway"></signalEventDefinition>
    </intermediateCatchEvent>
    <sequenceFlow id="sid-33278DBD-5F50-4827-9213-A4E22BB2939C" sourceRef="sid-C6B0BBD0-D2C9-4F94-B547-076D6D2611AC" targetRef="sid-08127570-1DFC-497B-900F-681D19FCA78B"></sequenceFlow>
    <sequenceFlow id="sid-633C7BA4-41A8-4325-80CD-2C37C0B430D1" sourceRef="sid-08127570-1DFC-497B-900F-681D19FCA78B" targetRef="sid-BE8A4B9D-AEA3-47BB-8576-9A95431313AD"></sequenceFlow>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_EventGatewayProcess_1">
    <bpmndi:BPMNPlane bpmnElement="EventGatewayProcess_1" id="BPMNPlane_EventGatewayProcess_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-C6B0BBD0-D2C9-4F94-B547-076D6D2611AC" id="BPMNShape_sid-C6B0BBD0-D2C9-4F94-B547-076D6D2611AC">
        <omgdc:Bounds height="40.0" width="40.0" x="225.0" y="175.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-BF8A0064-82EE-47E9-A977-59A9B7EDBE80" id="BPMNShape_sid-BF8A0064-82EE-47E9-A977-59A9B7EDBE80">
        <omgdc:Bounds height="31.0" width="31.0" x="405.0" y="90.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-BE8A4B9D-AEA3-47BB-8576-9A95431313AD" id="BPMNShape_sid-BE8A4B9D-AEA3-47BB-8576-9A95431313AD">
        <omgdc:Bounds height="40.0" width="40.0" x="525.0" y="178.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-1789888F-6F0D-48BF-9F3E-89C8D25DA753" id="BPMNShape_sid-1789888F-6F0D-48BF-9F3E-89C8D25DA753">
        <omgdc:Bounds height="28.0" width="28.0" x="615.0" y="184.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-08127570-1DFC-497B-900F-681D19FCA78B" id="BPMNShape_sid-08127570-1DFC-497B-900F-681D19FCA78B">
        <omgdc:Bounds height="30.0" width="30.0" x="405.5" y="255.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="sid-633C7BA4-41A8-4325-80CD-2C37C0B430D1" id="BPMNEdge_sid-633C7BA4-41A8-4325-80CD-2C37C0B430D1">
        <omgdi:waypoint x="435.49952002303877" y="270.1199961601843"></omgdi:waypoint>
        <omgdi:waypoint x="545.5" y="271.0"></omgdi:waypoint>
        <omgdi:waypoint x="545.5" y="217.5"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-9E68BD45-ACD2-43C0-87C7-D52F26F41F1F" id="BPMNEdge_sid-9E68BD45-ACD2-43C0-87C7-D52F26F41F1F">
        <omgdi:waypoint x="245.5" y="175.5"></omgdi:waypoint>
        <omgdi:waypoint x="245.5" y="106.0"></omgdi:waypoint>
        <omgdi:waypoint x="405.0" y="106.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-66CF7079-A547-4AB0-AE4D-5E7B0FD2CAFD" id="BPMNEdge_sid-66CF7079-A547-4AB0-AE4D-5E7B0FD2CAFD">
        <omgdi:waypoint x="437.0" y="106.0"></omgdi:waypoint>
        <omgdi:waypoint x="545.5" y="106.0"></omgdi:waypoint>
        <omgdi:waypoint x="545.5" y="178.5"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-33278DBD-5F50-4827-9213-A4E22BB2939C" id="BPMNEdge_sid-33278DBD-5F50-4827-9213-A4E22BB2939C">
        <omgdi:waypoint x="245.5" y="214.5"></omgdi:waypoint>
        <omgdi:waypoint x="245.5" y="271.0"></omgdi:waypoint>
        <omgdi:waypoint x="405.50024489196187" y="270.08571288633163"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-C03C593D-63B0-4464-9240-1EDF44F446D4" id="BPMNEdge_sid-C03C593D-63B0-4464-9240-1EDF44F446D4">
        <omgdi:waypoint x="564.6144578313254" y="198.3855421686747"></omgdi:waypoint>
        <omgdi:waypoint x="615.0002509882663" y="198.0838308324056"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-C593234B-2FEC-4B30-A21D-C297B10FF537" id="BPMNEdge_sid-C593234B-2FEC-4B30-A21D-C297B10FF537">
        <omgdi:waypoint x="120.0" y="195.0"></omgdi:waypoint>
        <omgdi:waypoint x="225.0" y="195.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>

当执行到达基于事件的网关时,将暂停进程执行。该流程实例订阅信号事件并创建一个在 5s 后触发的计时器。这样可以让流程在 5s 内的时间间隔等待信号触发,信号触发后,则取消定时器事件,否则执行定时器事件的后续流程。

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