第十五篇Flowable事件-信号事件
Posted 波波烤鸭
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了第十五篇Flowable事件-信号事件相关的知识,希望对你有一定的参考价值。
Flowable中的信号事件
1.开始事件
然后设置相关的属性,并定义一个信号
然后在我们声明的信号开始引用我们上面创建的信号
完整的xml文件
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:flowable="http://flowable.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.flowable.org/processdef" exporter="Flowable Open Source Modeler" exporterVersion="6.7.2">
<signal id="signal01" name="firstSignal" flowable:scope="global"></signal>
<process id="event2001" name="信号启动事件" isExecutable="true">
<startEvent id="start01" name="信号开始" isInterrupting="true">
<signalEventDefinition signalRef="signal01"></signalEventDefinition>
</startEvent>
<serviceTask id="task1" name="自动任务" flowable:class="com.bobo.flow.delegate.MyTwoJavaDelegate"></serviceTask>
<endEvent id="end01" name="结束"></endEvent>
<sequenceFlow id="sid-0FF05CCE-85CB-416C-8D36-A935AF9586C2" sourceRef="task1" targetRef="end01"></sequenceFlow>
<sequenceFlow id="sid-C8AD1AEE-5FCB-4419-8596-74532DD71ABC" sourceRef="start01" targetRef="task1"></sequenceFlow>
</process>
<bpmndi:BPMNDiagram id="BPMNDiagram_event2001">
<bpmndi:BPMNPlane bpmnElement="event2001" id="BPMNPlane_event2001">
<bpmndi:BPMNShape bpmnElement="start01" id="BPMNShape_start01">
<omgdc:Bounds height="30.0" width="30.0" x="285.0" y="172.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="task1" id="BPMNShape_task1">
<omgdc:Bounds height="80.0" width="100.0" x="467.5" y="147.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="end01" id="BPMNShape_end01">
<omgdc:Bounds height="28.0" width="28.0" x="612.5" y="173.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="sid-C8AD1AEE-5FCB-4419-8596-74532DD71ABC" id="BPMNEdge_sid-C8AD1AEE-5FCB-4419-8596-74532DD71ABC" flowable:sourceDockerX="15.0" flowable:sourceDockerY="15.0" flowable:targetDockerX="50.0" flowable:targetDockerY="40.0">
<omgdi:waypoint x="314.94999961358405" y="187.0"></omgdi:waypoint>
<omgdi:waypoint x="467.4999999999399" y="187.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="sid-0FF05CCE-85CB-416C-8D36-A935AF9586C2" id="BPMNEdge_sid-0FF05CCE-85CB-416C-8D36-A935AF9586C2" flowable:sourceDockerX="50.0" flowable:sourceDockerY="40.0" flowable:targetDockerX="14.0" flowable:targetDockerY="14.0">
<omgdi:waypoint x="567.449999999996" y="187.0"></omgdi:waypoint>
<omgdi:waypoint x="612.5" y="187.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>
部署流程:
/**
* Deploy
*/
@Test
void testDeploy() throws Exception
//RepositoryService repositoryService = processEngine.getRepositoryService();
Deployment deploy = repositoryService.createDeployment()
.addClasspathResource("信号启动事件.bpmn20.xml")
.name("信号启动事件")
.deploy();
System.out.println("deploy.getId() = " + deploy.getId());
System.out.println("deploy.getName() = " + deploy.getName());
System.out.println("部署开始的时间:" + new Date());
//TimeUnit.MINUTES.sleep(3);
流程是一个信息启动事件,所以我们需要释放对应的信号来触发流程的启动
/**
* 通过信号发送来触发信号启动事件的执行
* 全局的信息
*/
@Test
void signalReceived() throws Exception
runtimeService.signalEventReceived("firstSignal");
// 我们得保证容器的运行,所以需要阻塞
TimeUnit.MINUTES.sleep(1);
通过输出语句可以看到自定义任务触发了
我们可以把信息的作用域由原来的golbal全局的调整为processInstance,测试后发现还是执行了,说明在启动事件信息的作用域其实是不起作用的。
<signal id="signal01" name="firstSignal" flowable:scope="processInstance"></signal>
2.中间捕获事件
案例如下:当我们启动事件后,会阻塞在这个消息获取中间事件处,等待相关信号后才会继续流转。
对应的信号绑定
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:flowable="http://flowable.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.flowable.org/processdef" exporter="Flowable Open Source Modeler" exporterVersion="6.7.2">
<signal id="singnal02" name="secondSingal" flowable:scope="global"></signal>
<process id="event2002" name="信号中间捕获事件" isExecutable="true">
<startEvent id="start01" name="开始" flowable:formFieldValidation="true"></startEvent>
<intermediateCatchEvent id="signal01" name="信号捕获中间事件">
<signalEventDefinition signalRef="singnal02"></signalEventDefinition>
</intermediateCatchEvent>
<sequenceFlow id="sid-FBD95BC3-BA38-4863-95E6-E7D484FE80CB" sourceRef="start01" targetRef="signal01"></sequenceFlow>
<serviceTask id="task01" name="自动任务" flowable:class="com.bobo.flow.delegate.MyTwoJavaDelegate"></serviceTask>
<sequenceFlow id="sid-BF5FB671-5895-4FAC-8F92-E4BC4DEE821A" sourceRef="signal01" targetRef="task01"></sequenceFlow>
<endEvent id="end01" name="结束任务"></endEvent>
<sequenceFlow id="sid-4F4853C5-0FE6-48AB-BD80-A37CF807D90D" sourceRef="task01" targetRef="end01"></sequenceFlow>
</process>
<bpmndi:BPMNDiagram id="BPMNDiagram_event2002">
<bpmndi:BPMNPlane bpmnElement="event2002" id="BPMNPlane_event2002">
<bpmndi:BPMNShape bpmnElement="start01" id="BPMNShape_start01">
<omgdc:Bounds height="30.0" width="30.0" x="120.0" y="150.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="signal01" id="BPMNShape_signal01">
<omgdc:Bounds height="30.0" width="30.0" x="318.5" y="150.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="task01" id="BPMNShape_task01">
<omgdc:Bounds height="80.0" width="100.0" x="495.5" y="122.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="end01" id="BPMNShape_end01">
<omgdc:Bounds height="28.0" width="28.0" x="690.0" y="151.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="sid-BF5FB671-5895-4FAC-8F92-E4BC4DEE821A" id="BPMNEdge_sid-BF5FB671-5895-4FAC-8F92-E4BC4DEE821A" flowable:sourceDockerX="15.0" flowable:sourceDockerY="15.0" flowable:targetDockerX="50.0" flowable:targetDockerY="40.0">
<omgdi:waypoint x="348.44853390329115" y="164.78775666509335"></omgdi:waypoint>
<omgdi:waypoint x="495.49999999999903" y="162.7068396226415"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="sid-4F4853C5-0FE6-48AB-BD80-A37CF807D90D" id="BPMNEdge_sid-4F4853C5-0FE6-48AB-BD80-A37CF807D90D" flowable:sourceDockerX="50.0" flowable:sourceDockerY="40.0" flowable:targetDockerX="14.0" flowable:targetDockerY="14.0">
<omgdi:waypoint x="595.4499999999996" y="162.94542586750788"></omgdi:waypoint>
<omgdi:waypoint x="690.0016973189436" y="164.73506227304313"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<以上是关于第十五篇Flowable事件-信号事件的主要内容,如果未能解决你的问题,请参考以下文章