其他分享
首页 > 其他分享> > 使用Camunda流程引擎,关于并行网关(Parallel Gateway)使用

使用Camunda流程引擎,关于并行网关(Parallel Gateway)使用

作者:互联网

在使用开源Camunda流程引擎做二次开发时,网关是必须要接触的。在Camunda的 Modeler工具中提供了4种类型的网关:Exclusive Gateway(独占网关)、Parallel Gateway(并行网关)、Inclusive Gateway(包容性网关)、Event-based Gateway(基于事件的网关),每一个网关都有自己独特的功能,这一篇就先介绍  Parallel Gateway(并行网关)。

Parallel Gateway(并行网关)

The functionality of the parallel gateway is based on the incoming and outgoing sequence flow(s):

* fork: all outgoing sequence flows are followed in parallel, creating one concurrent execution for each sequence flow.

* join: all concurrent executions arriving at the parallel gateway wait at the gateway until an execution has arrived for each of the incoming sequence flows. Then the process continues past the joining gateway.

大概意思是:

并行网关的功能基于传入和传出序列流:

An important difference with other gateway types is that the parallel gateway does not evaluate conditions. If conditions are defined on the sequence flow connected with the parallel gateway, they are simply ignored.

重要提醒:与其他网关类型的一个重要区别是并行网关不评估条件。如果在与并行网关连接的序列流上定义条件,则会忽略它们。所以并行网关最重要的作用是连接。

流程实例

场景:公司里有请假的流程,先是组长审批,然后是经理审批、人事审批,只有都审批通过了,才会结束。

请假流程图:

并行网关不需要对节点做参数配置,做直接部署测试。

BPMN流程模型文件:

<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_1yxxu28" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="4.11.1" modeler:executionPlatform="Camunda Platform" modeler:executionPlatformVersion="7.15.0">

  <bpmn:process id="Process_0d8i21k" name="并行网关示例" isExecutable="true">
    <bpmn:startEvent id="StartEvent_1">
      <bpmn:outgoing>Flow_1dx1ok0</bpmn:outgoing>
    </bpmn:startEvent>
    <bpmn:parallelGateway id="Gateway_1vx1coa">

      <bpmn:incoming>Flow_0l0abn3</bpmn:incoming>

      <bpmn:outgoing>Flow_18egz2b</bpmn:outgoing>

      <bpmn:outgoing>Flow_0oed7gb</bpmn:outgoing>

    </bpmn:parallelGateway>

    <bpmn:sequenceFlow id="Flow_1dx1ok0" sourceRef="StartEvent_1" targetRef="Activity_1dut7sm" />

    <bpmn:endEvent id="Event_0rb2ozq">

      <bpmn:incoming>Flow_0ipw6rw</bpmn:incoming>

    </bpmn:endEvent>

    <bpmn:userTask id="Activity_1dut7sm" name="组长审批">

      <bpmn:incoming>Flow_1dx1ok0</bpmn:incoming>

      <bpmn:outgoing>Flow_0l0abn3</bpmn:outgoing>

    </bpmn:userTask>

    <bpmn:userTask id="Activity_1kl1xky" name="人事审批">

      <bpmn:incoming>Flow_0oed7gb</bpmn:incoming>

      <bpmn:outgoing>Flow_0ww5lb2</bpmn:outgoing>

    </bpmn:userTask>

    <bpmn:userTask id="Activity_0072g8y" name="经理审批">

      <bpmn:incoming>Flow_18egz2b</bpmn:incoming>

      <bpmn:outgoing>Flow_0aystu5</bpmn:outgoing>

    </bpmn:userTask>

    <bpmn:sequenceFlow id="Flow_0l0abn3" sourceRef="Activity_1dut7sm" targetRef="Gateway_1vx1coa" />

    <bpmn:parallelGateway id="Gateway_0xd48it">

      <bpmn:incoming>Flow_0aystu5</bpmn:incoming>

      <bpmn:incoming>Flow_0ww5lb2</bpmn:incoming>

      <bpmn:outgoing>Flow_0ipw6rw</bpmn:outgoing>

    </bpmn:parallelGateway>

    <bpmn:sequenceFlow id="Flow_18egz2b" sourceRef="Gateway_1vx1coa" targetRef="Activity_0072g8y" />

    <bpmn:sequenceFlow id="Flow_0oed7gb" sourceRef="Gateway_1vx1coa" targetRef="Activity_1kl1xky" />

    <bpmn:sequenceFlow id="Flow_0aystu5" sourceRef="Activity_0072g8y" targetRef="Gateway_0xd48it" />

    <bpmn:sequenceFlow id="Flow_0ww5lb2" sourceRef="Activity_1kl1xky" targetRef="Gateway_0xd48it" />

    <bpmn:sequenceFlow id="Flow_0ipw6rw" sourceRef="Gateway_0xd48it" targetRef="Event_0rb2ozq" />

  </bpmn:process>

  <bpmndi:BPMNDiagram id="BPMNDiagram_1">

    <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_0d8i21k">

      <bpmndi:BPMNEdge id="Flow_1dx1ok0_di" bpmnElement="Flow_1dx1ok0">

        <di:waypoint x="148" y="210" />

        <di:waypoint x="250" y="210" />

      </bpmndi:BPMNEdge>

      <bpmndi:BPMNEdge id="Flow_0l0abn3_di" bpmnElement="Flow_0l0abn3">

        <di:waypoint x="350" y="210" />

        <di:waypoint x="455" y="210" />

      </bpmndi:BPMNEdge>

      <bpmndi:BPMNEdge id="Flow_18egz2b_di" bpmnElement="Flow_18egz2b">

        <di:waypoint x="480" y="185" />

        <di:waypoint x="480" y="120" />

        <di:waypoint x="580" y="120" />

      </bpmndi:BPMNEdge>

      <bpmndi:BPMNEdge id="Flow_0oed7gb_di" bpmnElement="Flow_0oed7gb">

        <di:waypoint x="480" y="235" />

        <di:waypoint x="480" y="280" />

        <di:waypoint x="580" y="280" />

      </bpmndi:BPMNEdge>

      <bpmndi:BPMNEdge id="Flow_0aystu5_di" bpmnElement="Flow_0aystu5">

        <di:waypoint x="680" y="120" />

        <di:waypoint x="770" y="120" />

        <di:waypoint x="770" y="185" />

      </bpmndi:BPMNEdge>

      <bpmndi:BPMNEdge id="Flow_0ww5lb2_di" bpmnElement="Flow_0ww5lb2">

        <di:waypoint x="680" y="280" />

        <di:waypoint x="770" y="280" />

        <di:waypoint x="770" y="235" />

      </bpmndi:BPMNEdge>

      <bpmndi:BPMNEdge id="Flow_0ipw6rw_di" bpmnElement="Flow_0ipw6rw">

        <di:waypoint x="795" y="210" />

        <di:waypoint x="902" y="210" />

      </bpmndi:BPMNEdge>

      <bpmndi:BPMNShape id="Activity_1kl1xky_di" bpmnElement="Activity_1kl1xky">

        <dc:Bounds x="580" y="240" width="100" height="80" />

      </bpmndi:BPMNShape>

      <bpmndi:BPMNShape id="Activity_0072g8y_di" bpmnElement="Activity_0072g8y">

        <dc:Bounds x="580" y="80" width="100" height="80" />

      </bpmndi:BPMNShape>

      <bpmndi:BPMNShape id="Gateway_19csdge_di" bpmnElement="Gateway_1vx1coa">

        <dc:Bounds x="455" y="185" width="50" height="50" />

      </bpmndi:BPMNShape>

      <bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">

        <dc:Bounds x="112" y="192" width="36" height="36" />

      </bpmndi:BPMNShape>

      <bpmndi:BPMNShape id="Activity_1dut7sm_di" bpmnElement="Activity_1dut7sm">

        <dc:Bounds x="250" y="170" width="100" height="80" />

      </bpmndi:BPMNShape>

      <bpmndi:BPMNShape id="Event_0rb2ozq_di" bpmnElement="Event_0rb2ozq">

        <dc:Bounds x="902" y="192" width="36" height="36" />

      </bpmndi:BPMNShape>

      <bpmndi:BPMNShape id="Gateway_035arq3_di" bpmnElement="Gateway_0xd48it">

        <dc:Bounds x="745" y="185" width="50" height="50" />

      </bpmndi:BPMNShape>

    </bpmndi:BPMNPlane>

  </bpmndi:BPMNDiagram>

</bpmn:definitions>

部署流程并测试验证

流程发起后,第一个节点是组长审批。

并行网关不需要配置参数,即使配了也会被忽略,所以直接完成此节点后,会同时产生【经理审批】、【人事审批】任务

  

产生了这2个任务后,只有这2个任务都完成了此流程在会走到结束节点。

对并行网关就介绍到这里,下一篇是包容性网关介绍

标签:网关,Flow,流程,并行,Gateway,Camunda,gateway
来源: https://blog.csdn.net/weixin_44878554/article/details/123228416