Using Camunda process engine, about the use of Exclusive 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 first introduces Exclusive Gateway.
Exclusive Gateway
An exclusive gateway (also called the XOR gateway or, in more technical terms, the exclusive data-based gateway), is used to model a decision in the process. When the execution arrives at this gateway, all outgoing sequence flows are evaluated in the order in which they have been defined. The sequence flow which condition evaluates to 'true' (or which doesn't have a condition set, conceptually having a 'true' value defined on the sequence flow) is selected for continuing the process.
Exclusive gateway (also known as XOR gateway, or more technical exclusive data gateway) is used for decision-making in the modeling process. When execution reaches this gateway, all outgoing sequence flows are evaluated in the defined order. Select a sequence flow whose condition evaluation is "true" (or there is no condition set, and the "true" value is conceptually defined on the sequence flow) to continue the process.
One thing that needs special attention is the following sentence:
Note that only one sequence flow is selected when using the exclusive gateway. In case multiple sequence flow have a condition that evaluates to 'true', the first one defined in the XML is exclusively selected for continuing the process.
If no sequence flow can be selected (no condition evaluates to 'true') this will result in a runtime exception, unless you have a default flow defined. One default flow can be set on the gateway itself in case no other condition matches - like an 'else' in programming languages.
Please note that only one sequence stream can be selected when using an exclusive gateway. If more than one sequence flow has a condition that evaluates to "true", the first sequence flow defined in the XML will only be used to continue the process.
If you cannot select a sequence flow (no condition evaluates to "true"), this will cause a runtime exception unless you define a default flow. You can set a default flow on the gateway itself in case there are no other conditions to match -- such as "other" in the programming language.
Process instance
Scenario: there is a leave process in the company, which is first approved by the team leader. If the leave is more than 3 days, it is approved by the manager and then ended. If it is less than or equal to 3 days, it is directly approved by the HR department and then ended.
Leave flow chart:

 

Parameter configuration of saving condition:

 

 

After the process is initiated, it is first approved by the team leader. In the next node, you can choose whether to go to the manager for approval or personnel approval according to the days of leave. You can only choose one of two.
BPMN process model document
<?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_0qmx9bd" 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_0a6brl4" isExecutable="true">
    <bpmn:startEvent id="StartEvent_1" name="start">
      <bpmn:outgoing>Flow_0bsat4s</bpmn:outgoing>
    </bpmn:startEvent>
    <bpmn:userTask id="Activity_1rsws2h" name="Group leader approval">
      <bpmn:incoming>Flow_0bsat4s</bpmn:incoming>
      <bpmn:outgoing>Flow_14b6zp2</bpmn:outgoing>
    </bpmn:userTask>
    <bpmn:sequenceFlow id="Flow_0bsat4s" sourceRef="StartEvent_1" targetRef="Activity_1rsws2h" />
    <bpmn:exclusiveGateway id="Gateway_1njikuz">
      <bpmn:incoming>Flow_14b6zp2</bpmn:incoming>
      <bpmn:outgoing>Flow_0nag1ay</bpmn:outgoing>
      <bpmn:outgoing>Flow_1vwc1bq</bpmn:outgoing>
    </bpmn:exclusiveGateway>
    <bpmn:sequenceFlow id="Flow_0nag1ay" name="Less than or equal to 3 days" sourceRef="Gateway_1njikuz" targetRef="Activity_07vris1">
      <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">${isDays&lt;=3}</bpmn:conditionExpression>
    </bpmn:sequenceFlow>
    <bpmn:sequenceFlow id="Flow_1vwc1bq" name="More than 3 days" sourceRef="Gateway_1njikuz" targetRef="Activity_1nm1jj3">
      <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">${isDays&gt;3}</bpmn:conditionExpression>
    </bpmn:sequenceFlow>
    <bpmn:sequenceFlow id="Flow_14b6zp2" sourceRef="Activity_1rsws2h" targetRef="Gateway_1njikuz" />
    <bpmn:userTask id="Activity_07vris1" name="Personnel approval">
      <bpmn:incoming>Flow_0nag1ay</bpmn:incoming>
      <bpmn:outgoing>Flow_1kex2f5</bpmn:outgoing>
    </bpmn:userTask>
    <bpmn:userTask id="Activity_1nm1jj3" name="Manager approval">
      <bpmn:incoming>Flow_1vwc1bq</bpmn:incoming>
      <bpmn:outgoing>Flow_03hj1us</bpmn:outgoing>
    </bpmn:userTask>
    <bpmn:endEvent id="Event_14pjuff" name="end">
      <bpmn:incoming>Flow_03hj1us</bpmn:incoming>
    </bpmn:endEvent>
    <bpmn:sequenceFlow id="Flow_03hj1us" sourceRef="Activity_1nm1jj3" targetRef="Event_14pjuff" />
    <bpmn:endEvent id="Event_08elgeq" name="end">
      <bpmn:incoming>Flow_1kex2f5</bpmn:incoming>
    </bpmn:endEvent>
    <bpmn:sequenceFlow id="Flow_1kex2f5" sourceRef="Activity_07vris1" targetRef="Event_08elgeq" />
  </bpmn:process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_1">
    <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_0a6brl4">
      <bpmndi:BPMNEdge id="Flow_0bsat4s_di" bpmnElement="Flow_0bsat4s">
        <di:waypoint x="198" y="210" />
        <di:waypoint x="340" y="210" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_0nag1ay_di" bpmnElement="Flow_0nag1ay">
        <di:waypoint x="560" y="235" />
        <di:waypoint x="560" y="280" />
        <di:waypoint x="660" y="280" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="549" y="283" width="62" height="14" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_1vwc1bq_di" bpmnElement="Flow_1vwc1bq">
        <di:waypoint x="560" y="185" />
        <di:waypoint x="560" y="120" />
        <di:waypoint x="660" y="120" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="570" y="103" width="40" height="14" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_14b6zp2_di" bpmnElement="Flow_14b6zp2">
        <di:waypoint x="440" y="210" />
        <di:waypoint x="535" y="210" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_03hj1us_di" bpmnElement="Flow_03hj1us">
        <di:waypoint x="760" y="120" />
        <di:waypoint x="862" y="120" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="Flow_1kex2f5_di" bpmnElement="Flow_1kex2f5">
        <di:waypoint x="760" y="280" />
        <di:waypoint x="862" y="280" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
        <dc:Bounds x="162" y="192" width="36" height="36" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="169" y="235" width="22" height="14" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Activity_0fdhp45_di" bpmnElement="Activity_1rsws2h">
        <dc:Bounds x="340" y="170" width="100" height="80" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Gateway_1njikuz_di" bpmnElement="Gateway_1njikuz" isMarkerVisible="true">
        <dc:Bounds x="535" y="185" width="50" height="50" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Activity_0gxt3kl_di" bpmnElement="Activity_07vris1">
        <dc:Bounds x="660" y="240" width="100" height="80" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Event_08elgeq_di" bpmnElement="Event_08elgeq">
        <dc:Bounds x="862" y="262" width="36" height="36" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="869" y="305" width="22" height="14" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Activity_0gj23e9_di" bpmnElement="Activity_1nm1jj3">
        <dc:Bounds x="660" y="80" width="100" height="80" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="Event_14pjuff_di" bpmnElement="Event_14pjuff">
        <dc:Bounds x="862" y="102" width="36" height="36" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="869" y="145" width="22" height="14" />
        </bpmndi:BPMNLabel>
      </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.

 

After being approved by the team leader, it will go to the exclusive gateway node. It will go through manager approval or personnel approval according to the days of leave. Therefore, this step needs to submit the parameter: isDays

 

That's all for the exclusive gateway. The next article is about the parallel gateway

Keywords: Activiti

Added by MinDFreeZ on Wed, 02 Mar 2022 07:57:42 +0200