Asynchronous invocations and events

Now that we have explained the event handlers, let's look at another useful side of events. In real-world BPEL processes, a BPEL process often makes an asynchronous invocation of partner link services (as we already know from Chapter 5, Interaction Patterns in BPEL, these could be services or other BPEL processes). During an asynchronous invocation, the BPEL process first executes an <invoke> activity and then waits for the callback using <receive>.

However, the callback operation might not return a single operation call, such as onResult. Rather, the BPEL process should be able to wait for more than one callback operation, for example, onResult, onFault, and onEvent.

So far, we have seen how to define an event handler, which waits for incoming events parallel to the execution of the BPEL process flow. However, in scenarios where a BPEL process waits for the callback, using the event handler would make little sense. Therefore, BPEL provides another activity called <pick>.

We will learn how to use the <pick> activity to handle events related to callback invocations. To understand the <pick> activity, we will add another activity to our Book Warehousing BPEL process. So far, our process has queried the bookstores for stock quantity, selected the most appropriate bookstore, and asked a user to approve the bookstore selection using a human task.

We will task another activity to confirm that the books have been successfully warehoused. To achieve this, our Book Warehousing BPEL process will asynchronously invoke another service, which will respond to confirm whether the books have been successfully warehoused. This service, which we will call WarehousingConfirmation, will actually be another BPEL process, which will respond via a callback, confirming whether the books have been successfully warehoused. Let's start.

Implementing the WarehousingConfirmation service

To implement the WarehousingConfirmation service, we could use any programming language. However, as we are learning BPEL in this book, we will stick with BPEL and implement an asynchronous WarehousingConfirmationBPEL process. The BPEL process should make a callback using onResult for signaling successful or unsuccessful warehousing, but also provide onFault and onEvent callback operations.

The proposed WSDL port type declaration for the WarehousingConfirmationBPEL process is listed in the following screenshot:

Implementing the WarehousingConfirmation service

Have a go hero – implementing WarehousingConfirmation

It's your turn now. You should implement the WarehousingConfirmationBPEL process in the same way as we did earlier in this chapter. You can also refer to Chapter 5, Interaction Patterns in BPEL, for more information.

Invoking the WarehousingConfirmation service

We will now add the asynchronous invocation of the WarehousingConfirmationBPEL service to the Book Warehousing BPEL process. We will use the <invoke> activity to initiate the invocation. Then, we will use the <pick> activity to handle different incoming events from the callback.

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

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