在使用開源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個任務都完成了此流程才會走到結束節點。
對並行網關就介紹到這里,下一篇是包容性網關介紹