|Oracle® BPEL Process Manager Developer's Guide
Part Number B28981-03
This chapter describes how to use events and timeouts. Because Web services can take a long time to return a response, a BPEL process must be able to time out and continue with the rest of the flow after a period of time.
This chapter contains the following topics:
In this use case, you program a BPEL process to wait one minute for a response from the Star Loan Web service. If Star Loan does not respond in one minute, then the BPEL process automatically selects the United Loan offer. In the real world, the time limit is more like 48 hours. However, for this example, you do not want to wait that long to see if your BPEL process is working properly.
See Also:The following sample file:
Because asynchronous Web services can take a long time to return a response, a BPEL process must be able to time out, or give up waiting, and continue with the rest of the flow after a certain amount of time. You can use the pick activity to configure a BPEL flow to either wait a specified amount of time or to continue performing its duties. To set an expiration period for the time, you can use the wait activity.
If you plan to set timeouts for synchronous processes that connect to a remote database, you need to set the
syncMaxWaitTime timeout property in the
The pick activity provides two branches, each one with a condition. The branch that has its condition satisfied first is executed. In the following example, one branch's condition is to receive a loan offer, and the other branch's condition is to wait a specified amount of time.
Figure 10-1 provides an overview. The following activities take place:
An invoke activity initiates a service, in this case, a request for a loan offer from Star Loan.
The pick activity begins next. It has the following conditions:
onMessage: This condition has code for receiving a reply in the form of a loan offer from the Star Loan Web service. The onMessage code is the same as the code for receiving a response from the Star Loan Web service before a timeout was added.
onAlarm: This condition has code for a timeout of one minute. This time is defined as
PT1M, which means to wait one minute before timing out. In this timeout setting,
S stands for seconds,
M for one minute,
H for hour,
D for day, and
Y for year. In the unlikely event that you want a time limit of
3 days, and
15 seconds, you enter it as
PT1Y3D15S. The remainder of the code sets the loan variables selected and approved to
false, sets the annual percentage rate (APR) at
0.0, and copies this information into the
For more detailed information on the time duration format, see the duration section of the most current XML Schema Part 2: Datatypes document at:
The pick activity condition that completes first is the one that the BPEL process executes. The other branch then is not executed.
Figure 10-1 Overview of the Pick Activity
<pick> <!-- receive the result of the remote process --> <onMessage partnerLink="LoanService" portType="services:LoanServiceCallback" operation="onResult" variable="loanOffer"> <assign> <copy> <from variable="loanOffer" part="payload"/> <to variable="output" part="payload"/> </copy> </assign> </onMessage> <!-- wait for one minute, then timesout --> <onAlarm for="PT1M"> <assign> <copy> <from> <loanOffer xmlns="http://www.autoloan.com/ns/autoloan"> <providerName>Expired</providerName> <selected type="boolean">false</selected> <approved type="boolean">false</approved> <APR type="double">0.0</APR> </loanOffer> </from> <to variable="loanOffer" part="payload"/> </copy> </assign> </onAlarm> </pick>
wait activity allows a process to wait for a given time period or until a time limit has been reached. Exactly one of the expiration criteria must be specified.
<wait (for="duration-expr" | until="deadline-expr") standard-attributes> standard-elements </wait>
See Also:The following documentation for examples of defining a wait activity:
SleepBroker" for a demonstration that uses a wait activity
For synchronous processes that connect to a remote database, you must increase the
syncMaxWaitTime timeout property in the
<property id="syncMaxWaitTime"> <name>Delivery result receiver maximum wait time</name> <value>45</value> <comment> <![CDATA[The maximum time the process result receiver will wait for a result before returning. Results from asynchronous BPEL processes are retrieved synchronously via a receiver that will wait for a result from the container. <p/> The default value is 45 seconds.]]> </comment> </property>
To define a timeout, follow these steps:
Drag and drop a Pick activity into a BPEL process.
The Pick activity includes the onMessage (envelope icon) and onAlarm (alarm clock icon) branches.
Double-click the OnAlarm branch of the onAlarm activity and set its time limit to 1 minute instead of 1 hour.
Double-click the onMessage activity, and edit its attributes to receive the response from the loan service.
See Also:"Pick Activity"
Instead of performing multiple operations at the same time as with the flow attribute, you can use the pick activity to define a number of operations such that only the first one to complete is executed. The example in this chapter is of a pick activity where one branch is an asynchronous callback from a loan service, and the other branch is a timeout set at one minute.