流程引擎中 Send Task 和 Service Task 拥有相同的行为,都是通过回调Java代码完成相应逻辑。通常 Send Task 和 Receive Task 配合使用。 
 绘制一个 Send Task 流程,配置过程和 Service 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 消息,所以流程继续执行直到结束。