Time for action – adding an event handler to the BPEL process

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:

  1. Open the BookWarehousingBPEL.bpel process.
  2. On the left-hand side, we will select the Add OnAlarm icon, as shown in the following screenshot:
    Time for action – adding an event handler to the BPEL process
  3. Scroll to the right-hand side of the BPEL process and you should see that an OnAlarm event handler has been added to the BPEL process flow:
    Time for action – adding an event handler to the BPEL process
  4. We need to specify the deadline or duration expression for the OnAlarm event handler. Let's double-click on the OnAlarm icon. A pop-up EditOnAlarm window will appear, where we can specify For durations or Until deadlines. We could also specify Repeat Every duration, in which case the event handler would repeat every specified duration.
  5. Select the For duration and enter 15 Mins. Also, name the OnAlarm handler as Max Exec Time. Click on OK:
    Time for action – adding an event handler to the BPEL process

What just happened?

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:

What just happened?

Specifying alarm event activities

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:

Specifying alarm event activities

To notify the client that an event has occurred, we will add an onEvent operation on the callback interface.

Note

In asynchronous callback scenarios, it is a common practice that we specify several different operations on the callback port type, through which the BPEL process notifies the client about the possible outcomes. Typically, we specify onResult, onFault, and onEvent operations.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset