使用Camunda流程引擎,关于包容性网关(Inclusive Gateway)使用
在使用开源Camunda流程引擎做二次开发时,网关是必须要接触的。在Camunda的 Modeler工具中提供了4种类型的网关:Exclusive Gateway(独占网关)、Parallel Gateway(并行网关)、Inclusive Gateway(包容性网关)、Event-based Gateway(基于事件的网关),每一个网关都有自己独特的功能,这一篇就先介绍 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.
大概意思为:包容性网关可以被视为独家网关和并行网关的组合。与独家网关一样,您可以定义传出序列流的条件,包容性网关将对其进行评估。然而,主要区别在于,包容性网关可以接收多个序列流,如并行网关。
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’.
大概意思为:
包容性网关的功能基于传入和传出序列流:
-
叉子:评估所有传出序列流条件,对于评估为“真实”的序列流条件,并行跟踪流,为每个序列流创建一个并发执行。
-
连接:到达包容性网关的所有并发执行都在网关等待,直到每个具有进程令牌的传入序列流的执行到达。这是并行网关的一个重要区别。因此,换句话说,包容性网关只会等待执行的传入序列流。加入后,这个过程会继续通过加入包容性网关。
请注意,如果同一包容性网关有多个传入和传出序列流,则包容性网关可以同时具有 叉子 和 连接 行为。在这种情况下,网关将首先连接所有具有进程令牌的传入序列流,然后为具有计算为“true”条件的传出序列流分裂为多个并发执行路径。
总结:在输入、输出包容性网关的时候,包容性网关能够代替独占网关和并行网关。
流程实例
场景:公司里有请假的流程,先是组长审批,请假天数小于等于3天的只需要人事审批,而对大于3天的需要经理审批,并且对于大于等于5天的需要老板审批。老板需要知道一年中哪些人一次性请假超过5天的,好扣年终奖。
请假流程图:
节占条件参数配置:

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: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="包容性网关测试" 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="组长审批"> <bpmn:incoming>Flow_10ol650</bpmn:incoming> <bpmn:outgoing>Flow_1xvew9w</bpmn:outgoing> </bpmn:userTask> <bpmn:userTask id="Activity_1wsop74" name="人事审批"> <bpmn:incoming>Flow_1dkejle</bpmn:incoming> <bpmn:outgoing>Flow_1g3r6v4</bpmn:outgoing> </bpmn:userTask> <bpmn:userTask id="Activity_0fvflup" name="经理审批"> <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="大于3天" sourceRef="Gateway_1k9gcg8" targetRef="Activity_0fvflup"> <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">${isDays>3}</bpmn:conditionExpression> </bpmn:sequenceFlow> <bpmn:sequenceFlow id="Flow_1dkejle" name="小于等于3天" sourceRef="Gateway_1k9gcg8" targetRef="Activity_1wsop74"> <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">${isDays<=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="保存"> <bpmn:incoming>Flow_03yz94u</bpmn:incoming> <bpmn:outgoing>Flow_15r52g1</bpmn:outgoing> </bpmn:userTask> <bpmn:userTask id="Activity_1m3l1qx" name="老板审批"> <bpmn:incoming>Flow_09e96up</bpmn:incoming> <bpmn:outgoing>Flow_1ez2y5a</bpmn:outgoing> </bpmn:userTask> <bpmn:sequenceFlow id="Flow_09e96up" name="大于等于5天" sourceRef="Gateway_1k9gcg8" targetRef="Activity_1m3l1qx"> <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">${isDays>=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>
部署流程并测试验证
流程发起后,第一个节点是组长审批。
组长在完成审批的时候,现在想要达到【经理审批】、【老板审批】,就需要提交的请假天数大于等于5天,所以这里要设置参数请假的天数 isDays:5天
包容性网关就实现了我们想要的目的,既产生【经理审批】、【老板审批】
【经理审批】、【老板审批】都通过后,会流转到【保存】节点。到此包容性网关就完成分叉和汇聚的功能。
下一篇是 基于事件的网关(Event-based Gateway)介绍

浙公网安备 33010602011771号