Camunda流程引擎笔记(四):Send Task,Receive Task
文章目录
流程引擎中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回调类。
这里的
.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流程实例发送的消息。启动
Send 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消息,所以流程继续执行直到结束。
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论