How to use Camunda BPMN Send task and Receive Task

Elvis Whizzkid picture Elvis Whizzkid · Jun 18, 2014 · Viewed 9.5k times · Source

I am newbee in Camunda BPMN 2.0, i need help on how to implements and use send and receive task from one pool to another.

Answer

meyerdan picture meyerdan · Jun 18, 2014

Attach a JavaDelegate implementation to the send task:

<sendTask id="sendTask" camunda:class="org.camunda.bpm.MySendTaskDelegate" />

Inside the MySendTaskDelegate, correlate a message to the receive task in the other process instance:

public class MySendTaskDelegate implements JavaDelegate {

  public void execute(DelegateExecution execution) throws Exception {

    execution.getProcessEngineServices()
      .getRuntimeService()
      .createMessageCorrelation("someMessage")
      .processInstanceBusinessKey("someBusinessKey")
      .correlate();

  }

}

This assumes, that

  1. The waiting process instance has a businessKey of value someBusinessKey. The business key can be provided when starting the process instance.
  2. The waiting process instance has a receive Task with a message name someMessage. The message name for a receive task can be specified in BPMN 2.0 xml using the <message ... /> element. See: http://docs.camunda.org/latest/api-references/bpmn20/#tasks-receive-task