Tuesday, July 29, 2014

How to user correlations to Order messages in BPEL

How to user correlations to Order messages in BPEL


This small example will show how to use correlations to wait for a specific message to execute a second message, regardless of the order. Suppose that we have to operation one will insert and the other one will update a record. We need to execute the update first but not necessarily we are going to receive the insert first. When systems are distributed is hard to predict which message will arrive first.

  1. First step we are going to create an schema
Element ‘Type’ will contain the operation that we want to use, example INSERT or UPDATE
Element ‘Correlation ‘ will include a key that will group similar messages for the same operation
  1. Then we will create an EDN using the schema created befoer , we will call this EventEmail.edl
  2. I will create a bpel process (with the correlation code), one Mediator that will be instantiated by the EDN, one SOAP interface and a second mediator that will group all events assigned from the EDN and the SOAP interface.
SOAP interface is only for easy testing purposes
Composite structure will look like this
  1. Is important at composite level to set the property “bpel.config.reenableAggregationOnComplete”, this will allow us to reuse the same correlation as soon as one is closed

  1. Create the following BPEL , is important to notice that receiveInput will receive a correlation and OnMessage will receive the same correlation

  1. In the BPEL process we are going to create a correlation set with the following properties

Initiate for the first receive of the process, with an string property


Suppose we have a message
<ns1:email>
<ns1:type>INSERT</ns1:type>
<ns1:correlation>12</ns1:correlation>
</ns1:email>

The previous configuration will assign the value 12 as a correlated property so all messages receiving 12 will be group together.

Finally we are going to add an skip condition that indicates that only INSERT messages will be handled in the receive, so all messages that are not insert will be handled by the PICK

contains($inputVariable.payload/ns1:type,'INSERT')
  1. Finally we are going to add the same setup to the PICK activity without the skip condition and with NO on instantiate
  2. For testing We are going to send one message this two messages first UPDATE
<ns1:email>
<ns1:type>UPDATE</ns1:type>
<ns1:correlation>12</ns1:correlation>
</ns1:email>

After that insert
<ns1:email>
<ns1:type>INSERT</ns1:type>
<ns1:correlation>12</ns1:correlation>
</ns1:email>

The output will be the following,

As we can see the messages will be order and we can execute the logic properly