使用Camunda流程引擎,关于独占网关(Exclusive Gateway)使用

在使用开源Camunda流程引擎做二次开发时,网关是必须要接触的。在Camunda的 Modeler工具中提供了4种类型的网关:Exclusive Gateway(独占网关)、Parallel Gateway(并行网关)、Inclusive Gateway(包容性网关)、Event-based Gateway(基于事件的网关),每一个网关都有自己独特的功能,这一篇就先介绍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.
大概意思就是:网关(也称为XOR网关,或者更技术性的独数据网关)用于建模过程中的决策。当执行到达此网关时,所有传出序列流都按照定义顺序进行评估。选择条件评估为“true”(或没有条件集,在概念上在序列流上定义“true”值)的序列流以继续该过程。
其中需要特别注意的一点就是下面这句话:
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.
大概意思就是:请注意,使用独占网关时只能选择一个序列流。如果多个序列流具有计算为“true”的条件,则XML中定义的第一个序列流将仅用于继续该过程。
如果无法选择序列流(没有条件计算为“true”),除非您定义了默认流,否则这将导致运行时异常。可以在网关本身上设置一个默认流,以防没有其他条件匹配——例如编程语言中的“其他”。
流程实例
场景:公司里有请假的流程,先是组长审批,如果请假大于3天就是经理审批,然后结束,如果是小于等于3天就直接人事审批然后结束。
请假流程图:

 

节占条件参数配置:

 

 

流程发起后,先是组长审批,下一个节点是根据请假的天数选择是到经理审批还是人事审批,只能二选一。
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_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="开始">
      <bpmn:outgoing>Flow_0bsat4s</bpmn:outgoing>
    </bpmn:startEvent>
    <bpmn:userTask id="Activity_1rsws2h" name="组长审批">
      <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="小于等于3天" 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="大于3天" 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="人事审批">
      <bpmn:incoming>Flow_0nag1ay</bpmn:incoming>
      <bpmn:outgoing>Flow_1kex2f5</bpmn:outgoing>
    </bpmn:userTask>
    <bpmn:userTask id="Activity_1nm1jj3" name="经理审批">
      <bpmn:incoming>Flow_1vwc1bq</bpmn:incoming>
      <bpmn:outgoing>Flow_03hj1us</bpmn:outgoing>
    </bpmn:userTask>
    <bpmn:endEvent id="Event_14pjuff" name="结束">
      <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="结束">
      <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>

部署流程并测试验证

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

 

在组长审批后,就会走到独占网关节点,它会根据请假天数是走经理审批,还是人事审批,所以这一步需要提交参数:isDays

 

对独占网关就介绍到这里,下一篇是并行网关介绍
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

周周的JAVA技术栈

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值