Sunday, January 23, 2011

Implementing Correlation in BPM 11gR1 using BPEL

As far as I know, Oracle BPM 11g doesn't have an easy way to implement correlation sets and receive asynchronous messages in the middle of the process using some business information. But as Oracle BPM is in the top of Oracle SOA Suite infrastructure, we can use BPEL to achieve this behaviour. Using BPMN, Mediator and BPEL components together in a composite, we can expose 2 interfaces, one for start the business (BPMN) process and other to expose the asynchronous (BPEL) intermediate message, as I'll show below.

First of all, create a new BPM Project with a BPMN component.

In the "Create BPMN Process" dialog, import an external schema with data definition and define the input and output arguments.

Double click in the "Start" activity and create a new "Data Association".

Create a new "Business Process" variable using the same inputArg data type.

Copy the inputArg data to the new variable created.

Go back to the composite and add a new BPEL component. Select "Based on WSDL" template and define an asynchronous operation using the same external schema.

In the "Request" definition, select an element that has the unique business identifier that will be used to correlate the inbound intermediate operation.

In the "Callback" definition, select an element that define the same message that will be received in the middle of the process.

Uncheck the option "Expose as a SOAP service".

Open the WSDL generated for the BPEL process. Create a new one way operation in the inbound port type to receive the intermediate message in the BPEL process. Use the same callback message that will be returned by the BPEL process.

Open the BPEL process and create a new correlation set in the receiveInput activity.

Initialize the correlation set with the unique business identifier received.

Set the column "Initiate" to "Yes" (To get more informations about how to configure Correlation Sets in BPEL, click here).

Create a new Receive activity to receive the intermediate operation.

Select the intermediate operation and generate a new variable to receive the intermediate message.

Select the correlation set created previously.

Edit the correlation set to match the unique business identifier received in the intermediate message.

Add an Assign activity to the BPEL process to copy the message received in the intermediate operation to the output variable.

The BPEL process will looks like as the image below.

Go back to the composite, add a new Mediator component and select "Interface Definition from WSDL" template.

Define an one-way operation using the same external schema. In the "Request" definition, select the element that define the message that will be received in the middle of the process.

Connect the Mediator to the BPEL component, using the intermediateOperation of the BPEL component as the Target Operation.

Open the Mediator editor and create an Assign to route the received message. Keep the other configurations empty.

Go back to the BPMN diagram, add a Throw event after the Start event. In the "Implementation" tab, select "Message" as "Implementation Type" and "Service Call" in the "Implementation" properties.

Select the BPEL component interface as the service to be called and create a new "Data Association".

Copy the unique business identifier from the business process variable to the service input variable.

Add a new Catch event after the Throw event created. In the "Implementation" tab, select "Message" as "Implementation Type" and "Continues" as "Conversation" option. Select the throw event as "Initiator Node" and create a new "Data Association".

Create a new "Business Process" variable using the same data type as the intermediate operation returns. Copy the data received to the new variable created.

The final BPMN process will looks like this.

And the composite will looks like this.

Deploy the composite to the server and create a new instance of the business process calling the BPMN process interface.

See the execution flow trace.

Check that the BPMN process is waiting in the catch activity.

And the BPEL process is waiting in the receiveIntermediate activity.

Back to the Enterprise Manager, invoke the intermediateOperation through the Mediator interface.

Use the same unique business identifier used to initiate the business process.

See the execution flow trace again. Check that a new instance of the Mediator component was created, but the message was delivered to the BPEL instance created before (through correlation set).

Check that the BPEL instance finished, sending the received message to the caller process.

Check that the BPMN process received the callback message and finished successfully.

This idea can be extended to allow multiple intermediate messages being received during the business process execution. If all intermediate information to be received uses the same message, you can reuse the BPEL process, otherwise you can create additional BPEL components to receive different messages. Other improvement you can do is use the Mediator component in front of all the other components to expose a single interface (WSDL) and route each operation to the appropriate internal composite component.

To download this sample project, click here.


  1. Congratulations my friend Andrade for this post and your really useful blog!
    Someone also wrote a special thanks about this post here:

    For me also this was exactly what I was looking for, to solve a tricky problem related to catch message events in BPM.

    I only want to contribute a little bit: this solution can be even more simple: you don't need to use the Mediator if you expose the BPEL as a service.

    I'm just thinking in also have a technical blog (soon I hope), and I'll write some other tips related to this post.

  2. Thanks a lot my friend!

    About your suggestion to make things simple, you are right. You can just expose the BPEL interface as a service, but this will expose the whole interface (all operations), allowing to start the BPEL process from outside the composite. This is why I used the Mediator, to expose only the Intermediate operation and avoid that. If you imagine you may have more than one intermediate operation (more than one BPEL component), using the Mediator you can expose only one interface for all intermediate operations. In addition, you can expose the BPMN start operation together and have a single interface for the whole composite, using the Mediator to route all imbound messages. In my opinion this is the best choice.

    Before finish, I want to say "go ahead with your idea and start sharing with us your experiences and thoughts about how to use this technology properly". Will be very good have you writing too. When you do that, let me know. Will be a plesure include your blog in the right list I have :)


  3. Hi Andrade,this article is so good and it's so clear.I have one query regarding the correlation in BPM,how to set the correlation set in BPM.

  4. I only want to contribute a little bit: this solution can be even more simple: you don't need to use the Mediator if you expose the BPEL as a service.

  5. Hi,
    Thanks for your post, I have next problem, can you help me???:
    0Expression error: Empty string.javax.xml.xpath.XPathExpressionException: Expression error: Empty string. at oracle.xml.xpath.JXPath.compile( at oracle.xml.xpath.JXPath.evaluate( at com.collaxa.xml.XPathUtils.valueOf( at com.collaxa.cube.engine.ext.bpel.common.BPELWMPHelper.initiateCorrelationSet( ....

  6. This is very good, your reasoning behind the mediator is perfect. Thanks a lot for sharing this work.

    Good luck!!

    1. Arbitrator you can present only one program for all advanced functions. In addition, you can present I was very impressed and suggest some bet casino

  7. Thanks for the information.
    Can you please tell me how we can use mediator to capture the business event and route to BPM process?

  8. Correlation can be seen at