> ## Documentation Index
> Fetch the complete documentation index at: https://docs.aseeflow.org/llms.txt
> Use this file to discover all available pages before exploring further.

# 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.

<img src="https://mintcdn.com/aseeflow/OpLRJy6TPnBLn55c/img/short-codes/bpmn-receive-task.png?fit=max&auto=format&n=OpLRJy6TPnBLn55c&q=85&s=50f45dc643e6b2488ae02ad50c95440f" alt="" width="114" height="106" data-path="img/short-codes/bpmn-receive-task.png" />

A Receive Task with a message reference can be triggered like an ordinary event:

```xml theme={null}
<definitions ...>
  <message id="newInvoice" name="newInvoiceMessage"/>
  <process ...>
    <receiveTask id="waitState" name="wait" messageRef="newInvoice">
  ...
```

You can then either correlate the message:

```java theme={null}
// correlate the message
runtimeService.createMessageCorrelation(subscription.getEventName())
  .processInstanceBusinessKey("AB-123")
  .correlate();
```

Or explicitly query for the subscription and trigger it:

```java theme={null}
ProcessInstance pi = runtimeService.startProcessInstanceByKey("processWaitingInReceiveTask");

EventSubscription subscription = runtimeService.createEventSubscriptionQuery()
  .processInstanceId(pi.getId()).eventType("message").singleResult();

runtimeService.messageEventReceived(subscription.getEventName(), subscription.getExecutionId());
```

<Warning>
  Correlation of a parallel multi instance isn't possible because the subscription can't be identified unambiguously.
</Warning>

To continue a process instance that is currently waiting at a Receive Task without a message reference, the `runtimeService.signal(executionId)` can be called, using the id of the execution that arrived in the Receive Task.

```xml theme={null}
<receiveTask id="waitState" name="wait" />
```

The following code snippet shows how this works in practice:

```java theme={null}
ProcessInstance pi = runtimeService.startProcessInstanceByKey("receiveTask");
Execution execution = runtimeService.createExecutionQuery()
  .processInstanceId(pi.getId()).activityId("waitState").singleResult();

runtimeService.signal(execution.getId());
```

## ASEE Flow Extensions

<table class="table table-striped">
  <tr> <th>Attributes</th> <td> [camunda:asyncBefore](/reference/bpmn20/custom-extensions/extension-attributes#asyncbefore), [camunda:asyncAfter](/reference/bpmn20/custom-extensions/extension-attributes#asyncafter), [camunda:exclusive](/reference/bpmn20/custom-extensions/extension-attributes#exclusive), [camunda:jobPriority](/reference/bpmn20/custom-extensions/extension-attributes#jobpriority) </td> </tr>
  <tr> <th>Extension Elements</th> <td> [camunda:failedJobRetryTimeCycle](/reference/bpmn20/custom-extensions/extension-elements#failedjobretrytimecycle), [camunda:inputOutput](/reference/bpmn20/custom-extensions/extension-elements#inputoutput) </td> </tr>
  <tr> <th>Constraints</th> <td> The <code>camunda:exclusive</code> attribute is only evaluated if the attribute <code>camunda:asyncBefore</code> or <code>camunda:asyncAfter</code> is set to <code>true</code> </td> </tr>
</table>

## Additional Resources

* [Tasks](https://camunda.com/bpmn/reference/#activities-task) in the [BPMN 2.0 Modeling Reference](https://camunda.com/bpmn/reference/)
* [Message Receive Events](/reference/bpmn20/events/message-events)
* [Trigger a subscription via REST](/reference/rest/execution/trigger-execution)
