流程引擎中
Send Task
和
Service Task
拥有相同的行为,都是通过回调Java代码完成相应逻辑。通常
Send Task
和
Receive Task
配合使用。
一、Send Task
绘制一个Send Task
流程,配置过程和Service Task
一样。
二、Receive Task
A Receive Task is a simple task that waits for the arrival of a certain message. When the process execution arrives at a Receive Task, the process state is committed to the persistence storage. This means that the process will stay in this wait state until a specific message is received by the engine, which triggers continuation of the process beyond the Receive Task.
翻译:接收任务是一个简单的任务,它等待特定消息的到来。当流程执行到达接收任务时,流程状态被提交到持久性存储。这意味着流程将保持这种等待状态,直到引擎接收到特定的消息,这将触发Receive任务之外的流程继续。
简单来说就是流程到达Receive Task
节点后将持久化这个状态直到接收到一个特定的消息,才会继续往下走。
绘制一个Receive Task
流程。
三、测试
-
编写Java回调类并绑定给Send Task
。
这里的.createMessageCorrelation("message")
中配置了上面流程图中的Message Name
填写字符串。
而.processInstanceBusinessKey("messageBusinessKey")
中填写了一个特定的业务key,方便找到特定的Receive Task
流程。
public class SendTaskDelegate implements JavaDelegate {
@Override
public void execute(DelegateExecution execution) throws Exception {
execution.getProcessEngineServices()
.getRuntimeService()
.createMessageCorrelation("message")
.processInstanceBusinessKey("messageBusinessKey")
.correlate();
}
}
- 启动流程。
首先启动Send Task
流程可以看到以下错误:
很明显,这是提示我们需要首先启动一个Receive Task
流程实例以接收Send Task
流程实例发送的消息。
-
启动Receive Task
流程实例。
这里Business Key
填写了上面代码中配置的messageBusinessKey
。
访问http://localhost:8080/app/cockpit/default/#/dashboard
,可以看到有一个活动中的流程:
点击Running Process Instances
:
这里显示Receive Task
流程停止在了receive message
节点上。
接下来启动一个Send Task
流程实例:
再次访问http://localhost:8080/app/cockpit/default/#/dashboard
,可以看到已经没有执行中的流程了:
说明Receive Task
流程已经接受到了Send Task
流程发送的message
消息,所以流程继续执行直到结束。
注:内容在原文上有些许修改,修改后则不会报原文会报的错误。