Gopalan Suresh Raj's Web Cornucopia
An Oasis for the parched Enterprise Services Engineer/Developer

    WS-BPEL-Modeling Event-Handling in business processes

    WS-BPEL

    WS-BPEL allows you to achieve enterprise-agility by providing a mechanism to orchestrate and invoke disparate web services either synchronously or asynchronously. At runtime, these business processes will have to have the ability to handle disparate events. Business processes need to wait for incoming messages (or events) that trigger their execution. BPEL already provides the <receive> and <pick> activities that await incoming messages to kick off a new business process instance to execute as we saw in this blog entry. The <receive> activity allows the business process to wait for a specific type of message to arrive on a specified portType.

    For asynchronous business process invocations, results are usually returned back to the invoking business process instance using callback mechanisms. In such cases, the business process has to handle multiple types of incoming messages and provide the ability to define alternate paths to handle execution of the appropriate business logic. Since in most cases we are orchestrating a loosely-coupled service, we have to keep in mind that the web service we are invoking may not be available all the time. In such situations, we may need to model enough intelligence in the process to execute alternate paths. Therefore, the business process may need to wait for the callback for a specified duration (or a specified interval of time) before it can proceed with execution of other correctional activities that have to be executed. We can think of two different types of events that business processes may have to handle. They are:

    • Messages: Incoming messages that are the result of operation invocations by a partner process.
    • Alarms: Messages that are triggered by the same process after a specified time duration, or those that happen in response to a pre-defined date/time deadline.

    The <onMessage> element – Handling Incoming Messages:

    The <onMessage> element is very similar to the <receive> activity and takes the same set of attributes as the <receive> activity. The following skeletal code illustrates the <onMessage> element inside of a <pick> activity from the Travel Reservation Composite Application scenario described in this blog entry.

    ...
    <onMessage partnerLink="Hotel" 
               portType="hres:HotelReservationCallbackPortType" 
               operation="hotelReserved" 
               variable="HotelReservedIn">
      <correlations>
        <correlation set="ItineraryCorrelator"/>
      </correlations>
      <sequence name="HotelReserved">
        <assign name="CopyHotelReservation">
          <copy>
            <from variable="HotelReservedIn" part="itinerary"/>
            <to variable="ItineraryOut" part="itinerary"/>
          </copy>
        </assign>
      </sequence>
    </onMessage>
    ...
    

    The <onAlarm> element – Handling triggered events

    The <onAlarm> element is very similar to the element that we saw in this blog entry. It allows facilities to model for both a specific duration using the for attribute, or a deadline using the until attribute.

    It is therefore possible to model a deadline type of scenario where we want the business process to wait for a callback until a deadline occurs and then either throw a fault or perform other correctional business activities. It is also possible to model a duration type of scenario where we want the business process to wait for a certain amount of time duration and if no callback is received within this time, either throw a fault or perform other correctional business activities.

    The following skeletal code illustrates the <onAlarm> element inside of a <pick> activity from the Travel Reservation Composite Application scenario described in this blog entry.

    ...
    onAlarm>
      <for>'P3DT10H'</for>
      <sequence name="Timer">
         <assign name="CopyHotelCancellation">
          <copy>
            <from>$ReserveHotelIn.itinerary/ItineraryRef</from>
            <to variable="CancelHotelIn" part="itinerary"/>
          </copy>
        </assign>            
        <invoke name="CancelHotel" 
                partnerLink="Hotel" 
                portType="hres:HotelReservationPortType" 
                operation="cancelHotel" 
                inputVariable="CancelHotelIn" 
                outputVariable="CancelHotelOut"/>
      </sequence>
    </onAlarm>
    ...
    

    Look at this blog entry to understand what the value ‘P3DT10H’ means. The <onMessage> and the <onAlarm> elements can be used either inside a <pick> activity or in an <eventHandler> element.

    The screenshot below shows the <pick> activity and the <onMessage> and the <onAlarm> elements as modeled using the BPEL Visual Designer from the Travel Reservation Composite Application scenario described in this blog entry.

    The screen-shot below shows the WSDL for the Travel Reservation Composite Application scenario The screen-shot below shows the BPEL for the Travel Reservation Composite Application scenario
    Alt Alt

    Author Bibliography

    Gopalan Suresh Raj is a Senior Analyst, Software Architect, and Developer with expertise in multi-tiered systems development, enterprise service architectures, and distributed computing. He is also an active author, including contributions to Professional JMS Programming, Wrox Press, 2001, Enterprise Java Computing-Applications and Architecture, Cambridge University Press, 1999, and The Awesome Power of JavaBeans, Manning Publications Co., 1998. He has submitted papers at international fora, and his work has been published in numerous technical journals. Visit him at his Web Cornucopia© site (webcornucopia.com) or mail him at gopalan@webcornucopia.com.

    Back