Send and receive tasks
The send task allows you to send a message to a receive task in another process, and the receive task allows you to receive a message from a send task in another process. The send task is similar to the throw message event; however, you cannot use the send task to invoke a process that starts with a message start event. There are no send and receive tasks for signals, only for messages. Send and receive tasks also allow you to attach boundary events (which will be discussed in Chapter 4, Handling Exceptions) to them. This is an important difference.
You can use the receive task to start a process, however, in this case, you must set the Create Instance property and there must be a single start node of type "none" immediately before the receive task.
The following diagram shows three processes that use the methods we have discussed to communicate with each other. The dotted arrows indicate where throw and catch message events are used by Process3
to invoke Process1
, and by Process1
to return some data to Process3
when it is finished. The red arrows indicate where send and receive message tasks are used by Process1
to invoke Process2
, and by Process2
to return some data to Process1
when it is finished.
Let us consider what happens when an instance of Process3
is executed:
Process3
starts.Process3
throws a message event to startProcess1
.Right away,
Process3
goes on toActivity
.At the same time (more or less,)
Process1
starts.Process1
sends a message to startProcess2
.Right away,
Process1
goes on toDo something
.At the same time (more or less),
Process2
starts.Process2
goes on toDo something else
.While all of this is going on, when
Process3
finished doingActivity
, it went on toCatchEvent
and paused there waiting for a response back fromProcess1
.Similarly, when
Process1
finishedDo something
, it went on toReceiveTask
and paused there waiting for a response back fromProcess2
.When
Process2
finishedDo something else
, it sent a response (in this case by sending a message) back toProcess1
.Process1
wakes up upon receiving a response (message) fromProcess2
and then sends its response (by throwing a message event) back toProcess3
.Process3
wakes up upon receiving a response (catching a message event) fromProcess1
and then moves on to its end.