Using Camunda process engine, about the use of Inclusive Gateway

When using the open source camunda process engine for secondary development, the gateway must be contacted. Camunda's Modeler tool provides four types of gateways: Exclusive Gateway, Parallel Gateway, Inclusive Gateway and event based gateway. Each gateway has its own unique functions. This article will first introduce Parallel Gateway.

Inclusive Gateway

The Inclusive Gateway can be seen as a combination of an exclusive and a parallel gateway. Like an exclusive gateway, you can define conditions on outgoing sequence flows and the inclusive gateway will evaluate them. However, the main difference is that the inclusive gateway can receive more than one sequence flow, like a parallel gateway.

Inclusive gateway can be regarded as a combination of exclusive gateway and parallel gateway. Like the exclusive gateway, you can define the conditions of outgoing sequence flow, which will be evaluated by the inclusive gateway. However, the main difference is that inclusive gateways can receive multiple sequence streams, such as parallel gateways.

The functionality of the inclusive gateway is based on the incoming and outgoing sequence flows:

    * fork: all outgoing sequence flow conditions are evaluated and for the sequence flow conditions that evaluate to 'true', the flows are followed in parallel, creating one concurrent execution for each sequence flow.

    * join: all concurrent executions arriving at the inclusive gateway wait at the gateway until an execution has arrived for each of the incoming sequence flows that have a process token. This is an important difference to the parallel gateway. So in other words, the inclusive gateway will only wait for the incoming sequence flows that are executed. After the join, the process continues past the joining inclusive gateway.

Note that an inclusive gateway can have both fork and join behavior, if there are multiple incoming and outgoing sequence flows for the same inclusive gateway. In that case, the gateway will first join all incoming sequence flows that have a process token, before splitting into multiple concurrent paths of executions for the outgoing sequence flows that have a condition that evaluates to 'true'.

It roughly means:

The functionality of the inclusive gateway is based on incoming and outgoing sequence flows:

  • Fork: evaluate all outgoing sequence flow conditions. For the sequence flow conditions evaluated as "real", track the flow in parallel and create a concurrent execution for each sequence flow.

  • Connection: all concurrent executions arriving at the inclusive gateway wait at the gateway until the execution of each incoming sequence flow with process token arrives. This is an important difference between parallel gateways. Therefore, in other words, the inclusive gateway will only wait for the incoming sequence flow to be executed. After joining, this process will continue through joining the inclusive gateway.

Note that if there are multiple incoming and outgoing sequence flows in the same inclusive gateway, the inclusive gateway can have both # fork # and # connection # behaviors. In this case, the gateway will first connect all incoming sequence flows with process tokens, and then split into multiple concurrent execution paths for outgoing sequence flows with "true" conditions.

Conclusion: when inputting and outputting inclusive gateway, inclusive gateway can replace exclusive gateway and parallel gateway.

Process instance

Scenario: there is a leave process in the company. First, it is approved by the team leader. Only personnel approval is required for leave days less than or equal to 3 days, manager approval is required for leave days greater than 3 days, and boss approval is required for leave days greater than or equal to 5 days. The boss needs to know who takes more than five days off at one time in a year, so as to deduct the year-end bonus.

Leave flow chart:

 

Parameter configuration of saving condition:

 

 

BPMN process model file:

<?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:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_0pijek2" 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_0zkorla" name="Inclusive gateway test" isExecutable="true">

    <bpmn:startEvent id="Event_00hn1zz">

      <bpmn:outgoing>Flow_10ol650</bpmn:outgoing>

    </bpmn:startEvent>

    <bpmn:endEvent id="Event_0rlc15d">

      <bpmn:incoming>Flow_15r52g1</bpmn:incoming>

    </bpmn:endEvent>

    <bpmn:userTask id="Activity_1bhicu5" name="Group leader approval">

      <bpmn:incoming>Flow_10ol650</bpmn:incoming>

      <bpmn:outgoing>Flow_1xvew9w</bpmn:outgoing>

    </bpmn:userTask>

    <bpmn:userTask id="Activity_1wsop74" name="Personnel approval">

      <bpmn:incoming>Flow_1dkejle</bpmn:incoming>

      <bpmn:outgoing>Flow_1g3r6v4</bpmn:outgoing>

    </bpmn:userTask>

    <bpmn:userTask id="Activity_0fvflup" name="Manager approval">

      <bpmn:incoming>Flow_0gamcen</bpmn:incoming>

      <bpmn:outgoing>Flow_0jxg79k</bpmn:outgoing>

    </bpmn:userTask>

    <bpmn:sequenceFlow id="Flow_10ol650" sourceRef="Event_00hn1zz" targetRef="Activity_1bhicu5" />

    <bpmn:sequenceFlow id="Flow_1xvew9w" sourceRef="Activity_1bhicu5" targetRef="Gateway_1k9gcg8" />

    <bpmn:sequenceFlow id="Flow_0gamcen" name="More than 3 days" sourceRef="Gateway_1k9gcg8" targetRef="Activity_0fvflup">

      <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">${isDays&gt;3}</bpmn:conditionExpression>

    </bpmn:sequenceFlow>

    <bpmn:sequenceFlow id="Flow_1dkejle" name="Less than or equal to 3 days" sourceRef="Gateway_1k9gcg8" targetRef="Activity_1wsop74">

      <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">${isDays&lt;=3}</bpmn:conditionExpression>

    </bpmn:sequenceFlow>

    <bpmn:sequenceFlow id="Flow_03yz94u" sourceRef="Gateway_0cdw7jc" targetRef="Activity_1azj6fl" />

    <bpmn:sequenceFlow id="Flow_1g3r6v4" sourceRef="Activity_1wsop74" targetRef="Gateway_0cdw7jc" />

    <bpmn:sequenceFlow id="Flow_0jxg79k" sourceRef="Activity_0fvflup" targetRef="Gateway_0cdw7jc" />

    <bpmn:sequenceFlow id="Flow_15r52g1" sourceRef="Activity_1azj6fl" targetRef="Event_0rlc15d" />

    <bpmn:userTask id="Activity_1azj6fl" name="preservation">

      <bpmn:incoming>Flow_03yz94u</bpmn:incoming>

      <bpmn:outgoing>Flow_15r52g1</bpmn:outgoing>

    </bpmn:userTask>

    <bpmn:userTask id="Activity_1m3l1qx" name="Boss approval">

      <bpmn:incoming>Flow_09e96up</bpmn:incoming>

      <bpmn:outgoing>Flow_1ez2y5a</bpmn:outgoing>

    </bpmn:userTask>

    <bpmn:sequenceFlow id="Flow_09e96up" name="5 days or more" sourceRef="Gateway_1k9gcg8" targetRef="Activity_1m3l1qx">

      <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">${isDays&gt;=5}</bpmn:conditionExpression>

    </bpmn:sequenceFlow>

    <bpmn:sequenceFlow id="Flow_1ez2y5a" sourceRef="Activity_1m3l1qx" targetRef="Gateway_0cdw7jc" />

    <bpmn:inclusiveGateway id="Gateway_1k9gcg8">

      <bpmn:incoming>Flow_1xvew9w</bpmn:incoming>

      <bpmn:outgoing>Flow_0gamcen</bpmn:outgoing>

      <bpmn:outgoing>Flow_1dkejle</bpmn:outgoing>

      <bpmn:outgoing>Flow_09e96up</bpmn:outgoing>

    </bpmn:inclusiveGateway>

    <bpmn:inclusiveGateway id="Gateway_0cdw7jc">

      <bpmn:incoming>Flow_1g3r6v4</bpmn:incoming>

      <bpmn:incoming>Flow_0jxg79k</bpmn:incoming>

      <bpmn:incoming>Flow_1ez2y5a</bpmn:incoming>

      <bpmn:outgoing>Flow_03yz94u</bpmn:outgoing>

    </bpmn:inclusiveGateway>

  </bpmn:process>

  <bpmndi:BPMNDiagram id="BPMNDiagram_1">

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

      <bpmndi:BPMNEdge id="Flow_10ol650_di" bpmnElement="Flow_10ol650">

        <di:waypoint x="188" y="230" />

        <di:waypoint x="270" y="230" />

      </bpmndi:BPMNEdge>

      <bpmndi:BPMNEdge id="Flow_1xvew9w_di" bpmnElement="Flow_1xvew9w">

        <di:waypoint x="370" y="230" />

        <di:waypoint x="445" y="230" />

      </bpmndi:BPMNEdge>

      <bpmndi:BPMNEdge id="Flow_0gamcen_di" bpmnElement="Flow_0gamcen">

        <di:waypoint x="470" y="205" />

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

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

        <bpmndi:BPMNLabel>

          <dc:Bounds x="530" y="103" width="40" height="14" />

        </bpmndi:BPMNLabel>

      </bpmndi:BPMNEdge>

      <bpmndi:BPMNEdge id="Flow_1dkejle_di" bpmnElement="Flow_1dkejle">

        <di:waypoint x="495" y="230" />

        <di:waypoint x="620" y="230" />

        <bpmndi:BPMNLabel>

          <dc:Bounds x="527" y="212" width="62" height="14" />

        </bpmndi:BPMNLabel>

      </bpmndi:BPMNEdge>

      <bpmndi:BPMNEdge id="Flow_03yz94u_di" bpmnElement="Flow_03yz94u">

        <di:waypoint x="835" y="230" />

        <di:waypoint x="890" y="230" />

      </bpmndi:BPMNEdge>

      <bpmndi:BPMNEdge id="Flow_1g3r6v4_di" bpmnElement="Flow_1g3r6v4">

        <di:waypoint x="720" y="230" />

        <di:waypoint x="785" y="230" />

      </bpmndi:BPMNEdge>

      <bpmndi:BPMNEdge id="Flow_0jxg79k_di" bpmnElement="Flow_0jxg79k">

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

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

        <di:waypoint x="810" y="205" />

      </bpmndi:BPMNEdge>

      <bpmndi:BPMNEdge id="Flow_15r52g1_di" bpmnElement="Flow_15r52g1">

        <di:waypoint x="990" y="230" />

        <di:waypoint x="1032" y="230" />

      </bpmndi:BPMNEdge>

      <bpmndi:BPMNEdge id="Flow_09e96up_di" bpmnElement="Flow_09e96up">

        <di:waypoint x="470" y="255" />

        <di:waypoint x="470" y="340" />

        <di:waypoint x="620" y="340" />

        <bpmndi:BPMNLabel>

          <dc:Bounds x="499" y="313" width="62" height="14" />

        </bpmndi:BPMNLabel>

      </bpmndi:BPMNEdge>

      <bpmndi:BPMNEdge id="Flow_1ez2y5a_di" bpmnElement="Flow_1ez2y5a">

        <di:waypoint x="720" y="340" />

        <di:waypoint x="810" y="340" />

        <di:waypoint x="810" y="255" />

      </bpmndi:BPMNEdge>

      <bpmndi:BPMNShape id="Event_00hn1zz_di" bpmnElement="Event_00hn1zz">

        <dc:Bounds x="152" y="212" width="36" height="36" />

      </bpmndi:BPMNShape>

      <bpmndi:BPMNShape id="Event_0rlc15d_di" bpmnElement="Event_0rlc15d">

        <dc:Bounds x="1032" y="212" width="36" height="36" />

      </bpmndi:BPMNShape>

      <bpmndi:BPMNShape id="Activity_0jdk70q_di" bpmnElement="Activity_1azj6fl">

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

      </bpmndi:BPMNShape>

      <bpmndi:BPMNShape id="Activity_1wsop74_di" bpmnElement="Activity_1wsop74">

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

      </bpmndi:BPMNShape>

      <bpmndi:BPMNShape id="Activity_1bhicu5_di" bpmnElement="Activity_1bhicu5">

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

      </bpmndi:BPMNShape>

      <bpmndi:BPMNShape id="Activity_08s10xr_di" bpmnElement="Activity_1m3l1qx">

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

      </bpmndi:BPMNShape>

      <bpmndi:BPMNShape id="Activity_0fvflup_di" bpmnElement="Activity_0fvflup">

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

      </bpmndi:BPMNShape>

      <bpmndi:BPMNShape id="Gateway_0ymo95d_di" bpmnElement="Gateway_1k9gcg8">

        <dc:Bounds x="445" y="205" width="50" height="50" />

      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Gateway_0a0ldpu_di" bpmnElement="Gateway_0cdw7jc">
        <dc:Bounds x="785" y="205" width="50" height="50" />
      </bpmndi:BPMNShape>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</bpmn:definitions>

Deploy process and test validation

After the process is initiated, the first node is approved by the team leader.

When the approval days set by the boss is greater than the approval days set by the boss and the approval days set by the boss, the number of days to leave is 5 days. Therefore, when the approval days set by the boss is completed, the number of days to leave is 5 days

 

The inclusive gateway achieves the purpose we want, including [manager approval] and [boss approval]

After both manager approval and boss approval are approved, the flow will be transferred to the save node. At this point, the inclusive gateway completes the functions of bifurcation and convergence.

The next article is about {event based gateway

Keywords: Java Spring Boot Activiti

Added by toms100 on Fri, 04 Mar 2022 08:38:16 +0200