Event handling is an activity that runs concurrently with a scope. Events can be one of two types: a message event or an alarm. When a message event or alarm occurs, the event handler associated with it invokes an activity.
Event handlers are especially helpful for events and requests that cannot be scheduled relative to the main activity, but may occur at unpredictable times. For example, a customer can cancel an order that is being processed.
Event handlers are considered part of the normal behavior of the scope, unlike fault and compensation handlers that take over normal processing.
An event handler can be attached to the process as a whole or to a scope. One or more events can occur and be handled at any time while the corresponding scope is active.
An event handler cannot be enabled until a process instance is created, meaning it cannot create the process instance itself.
An event can be an incoming message that corresponds to a request/response or one-way operation in a WSDL. For example, a status query is likely to be a request/response operation, whereas a cancellation can be a one-way operation.
An event can also be an alarm that goes off after a set time or lasts for a specified time, and optionally repeats.
Examples of Event Handler Activities
When a message that triggers an event is received, one of the following can be the likely response by an event handler:
Send a reply.
Terminate the process instance. For example, an order is cancelled, so the process instance should be cancelled, and there is no ongoing work to be undone and compensated.
Throw a fault to cause the ongoing work to be undone and compensated.