Camunda子流程有两种实现方式:嵌套子流程(Embedded Subprocess)和外部子流程(Call Activity)。以下是Camunda外部子流程(Call Activity)的实现方式。
第一步创建外部流程(发送email)
1、首先编写java email类并发布,后边编辑流程会用到(图中标红部分是获取流程内param的方法)。
注:MailUtil必须实现JavaDelegate

2、拖入开始节点,定义form表单,增加三个参数to(收件人)、title(邮件标题)、text(邮件内容)这样EmailUtil代码里就能获取到参数。

3、拖入task,点击扳手图标选择Service Task。

Implementation选择Java Class,Java Class列填刚才写的MailUtil路径

4、保存发布(REST Endpoint填自己camunda引擎部署地址)

以下是完整email流程xml
<?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:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_11zp891" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="4.12.0" modeler:executionPlatform="Camunda Platform" modeler:executionPlatformVersion="7.15.0">
<bpmn:process id="Process_0coyx3r" name="邮件" isExecutable="true">
<bpmn:startEvent id="StartEvent_1" camunda:formKey="">
<bpmn:extensionElements>
<camunda:formData>
<camunda:formField id="to" label="收件人" type="string" />
<camunda:formField id="title" label="标题" type="string" />
<camunda:formField id="text" label="内容" type="string" />
</camunda:formData>
</bpmn:extensionElements>
<bpmn:outgoing>Flow_1q3wq2o</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:sequenceFlow id="Flow_1q3wq2o" sourceRef="StartEvent_1" targetRef="Activity_0qd4r5l" />
<bpmn:serviceTask id="Activity_0qd4r5l" name="邮件发送" camunda:class="com.xxx.MailUtil">
<bpmn:incoming>Flow_1q3wq2o</bpmn:incoming>
<bpmn:outgoing>Flow_15ookz3</bpmn:outgoing>
</bpmn:serviceTask>
<bpmn:endEvent id="Event_0wj7w1h">
<bpmn:incoming>Flow_15ookz3</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id="Flow_15ookz3" sourceRef="Activity_0qd4r5l" targetRef="Event_0wj7w1h" />
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_0coyx3r">
<bpmndi:BPMNEdge id="Flow_1q3wq2o_di" bpmnElement="Flow_1q3wq2o">
<di:waypoint x="188" y="117" />
<di:waypoint x="440" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_15ookz3_di" bpmnElement="Flow_15ookz3">
<di:waypoint x="540" y="117" />
<di:waypoint x="672" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
<dc:Bounds x="152" y="99" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1g5eare_di" bpmnElement="Activity_0qd4r5l">
<dc:Bounds x="440" y="77" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_0wj7w1h_di" bpmnElement="Event_0wj7w1h">
<dc:Bounds x="672" y="99" width="36" height="36" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
第二步创建新流程
1、拖入task后点击扳手选择 Call Activity

2、 Call Activity选择BPMN,Called Element是刚才创建好邮件发送流程的id,Binding可以选择调用最后一个版本,也可以指定版本

完整xml
<?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_0z66ebo" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="4.12.0" modeler:executionPlatform="Camunda Platform" modeler:executionPlatformVersion="7.15.0">
<bpmn:process id="Process_1m5rpyw" isExecutable="true">
<bpmn:startEvent id="StartEvent_1">
<bpmn:outgoing>Flow_044c2ou</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:sequenceFlow id="Flow_044c2ou" sourceRef="StartEvent_1" targetRef="Activity_0qlvkfa" />
<bpmn:callActivity id="Activity_0qlvkfa" name="测试发邮件" calledElement="Process_0coyx3r">
<bpmn:incoming>Flow_044c2ou</bpmn:incoming>
<bpmn:outgoing>Flow_1koshjv</bpmn:outgoing>
</bpmn:callActivity>
<bpmn:endEvent id="Event_1koqt3y">
<bpmn:incoming>Flow_1koshjv</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id="Flow_1koshjv" sourceRef="Activity_0qlvkfa" targetRef="Event_1koqt3y" />
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1m5rpyw">
<bpmndi:BPMNEdge id="Flow_044c2ou_di" bpmnElement="Flow_044c2ou">
<di:waypoint x="215" y="117" />
<di:waypoint x="270" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1koshjv_di" bpmnElement="Flow_1koshjv">
<di:waypoint x="370" y="117" />
<di:waypoint x="632" y="117" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
<dc:Bounds x="179" y="99" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1yak16a_di" bpmnElement="Activity_0qlvkfa">
<dc:Bounds x="270" y="77" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_1koqt3y_di" bpmnElement="Event_1koqt3y">
<dc:Bounds x="632" y="99" width="36" height="36" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
3、保存发布
第三步测试
访问camunda引擎地址在tasklist里点击Start process 选择刚才保存的流程

输入参数后start

收到邮件

470

被折叠的 条评论
为什么被折叠?



