Let's now add an event handler to the main Book Warehousing BPEL process. First, we will add an alarm event handler for the maximal execution time of a BPEL process. Then, we will add a message event handler, which will allow the cancelation of a running BPEL process instance.
We will proceed as follows:
BookWarehousingBPEL.bpel
process.Max Exec Time
. Click on OK:We have added an OnAlarm event handler to our BPEL process. We have specified that the alarm event will trigger 15 minutes after the BPEL process instance is initiated. The following code has been added to the BPEL process:
Now that we have added the alarm event handler, we have to specify what will happen when the alarm event is triggered. We specify this by putting activities within the event handler scope.
For this example, we will notify the client that an event has occurred and then we will terminate the process. In a more sophisticated process, we could notify a user (for example, through a human task) or we could do a more sophisticated action.
To notify the client that an event has happened, we first have to decide how we will do the notification. As this is an asynchronous BPEL process, we will use the <invoke>
activity to return the result through a callback. We have specified an onResult
operation on the callback WSDL port, as shown in the following screenshot:
To notify the client that an event has occurred, we will add an onEvent
operation on the callback interface.