A Quick Response

A Quick Response

Returning an Immediate Response from an Asynch Process

I just got asked by a colleague how to return an immediate response from a BPEL process created using the template "Asynchronous BPEL Process".  Often we want to return some data to the caller of a process to indicate that the request has been received and is being processed.  To do this we need to add an immediate response to the caller in addition to calling them back later when the process is completed.  For example consider a process to make a booking for some resource.  The process might be lengthy and the caller may need some mechanism for canceling the process before it completes.  In this case returning an immediate response could give the caller a handle allowing him to call back into the specific process instance to cancel it.
So lets look at how we alter the template to allow for this immediate response.

Create the Project

First we create our process using File->New Project in JDeveloper and choose a BPEL PRocess Project and select the "Asynchronous BPEL Process" template.

Adding a Response Element

Once we have created our project we then need to add an immediate response element to the XSD.
    <element name="ImmediateResponseBPELProcessProcessImmediateResponse">
                <element name="result" type="string"/>

Adding a New Message Type

Having created a new immediate response element to the XSD we then need to use that element within a new message type in the WSDL.
    <message name="ImmediateResponseBPELProcessImmediateResponseMessage">
        <part name="payload" element="client:ImmediateResponseBPELProcessProcessImmediateResponse"/>

Adding an Output to the Initiate Operation

Within the port type for the process we need to modify the "initiate" operation to return an immediate response of the message type we just created.
        <operation name="initiate">
            <input message="client:ImmediateResponseBPELProcessRequestMessage"/>
            <output message="client:ImmediateResponseBPELProcessImmediateResponseMessage"/>

Adding a New Variable to the Process

We need to add a new variable to the process to hold the immediate return value.

Add a Reply to the Process

We can add the reply operation to the process and wire it up the client partner link.

Complete Process

Finally we need to complete the process.  I will often return the process instance ID as a return value.  This can then be used a correlation token if the client needs to call into the process again before it completes.

Once the process is finished being written it can be deployed and executed.

Remind Me Why Again

So adding an immediate response lets us confirm to the caller that we have received their request and also gives them a token to call back into the process later.  A complete example is uploaded here.  As you can see it is very easy to do and personally I feel all "asynchronous" processes should give some immediate response.


Let's consider that it allows the client to make a call later. As you suggested, we could receive a Cancel before the 5 minutes have elapsed, and taking appropriate actions. For instance, you have WaitFor5 and a Receive activity under a Flow. The Receive activity would react from a Cancel action, but: - how to you define this new cancel action? Under the same client partnerlink ? How would you do this? Or maybe with another partnerlink ? - how BPEL PM is able to 'match' between the started instance and the instance you try to cancel? How do you use the token (instanceID) when you call Cancel ? Thanks Stephane

Posted by Stephane D. on October 01, 2007 at 04:42 AM MDT #

Obviously, it is not a Flow that must be created, but a Pick activity with: - onAlarm: set the time to 5 min as per the example, and have the assign activity for the timed out process flow. - onMessage: set to the cancel action with the related assign activity (cancelled process). 1) I have defined the new action 'cancel' and related message type and input variable, but I get "Cannot find operation in portType. The operation "cancel" is not found in portType" 2) How the call to "cancel" will be correlated to exactly reference this instance of the process we want the onMessage to be invoked ?

Posted by Stephane D. on October 02, 2007 at 02:43 AM MDT #

Hello Antony, I just read your blog "A Quick Response". i have not tried deploying this But i got many doubts raised in my mind after reading this. As per BPEL documentation, In Asynchronous case, client thread is immediately returnted after the message is given to the worker bean and a new thread is started. How can Reply Activity returns the response to the same client that made the request. Thanks/Chandra

Posted by Chandra on November 10, 2007 at 04:49 AM MST #

You are confusing the message interaction pattern with the BPEL pattern.  If you follow my entry you will see that we change the initial interaction pattern from a one-way to a two-way interaction.  BPEL will processing this inline on the receiving thread rather than using a seperate worker thread which as you indicate is what happens with a one-way interaction.
BPEL figures out what to do based on the message interaction pattern.
I can assure you that it doies work as I said, try it yourself.

Hope that helps

Posted by Antony Reynolds on December 05, 2007 at 12:19 AM MST #

This example does not mention updating the bindings to include and <output> in the soap:operation for the soapAction (initiate). I was able to incorporate your suggestions into my own project, as well as changes to the binding, and it worked great! Thanks.

Posted by Dezi Siliezar on January 15, 2008 at 02:49 AM MST #

Post a Comment:
Comments are closed for this entry.

Musings on Fusion Middleware and SOA Picture of Antony Antony works with customers across the US and Canada in implementing SOA and other Fusion Middleware solutions. Antony is the co-author of the SOA Suite 11g Developers Cookbook, the SOA Suite 11g Developers Guide and the SOA Suite Developers Guide.


« April 2014