Friday, June 5, 2009

Rollbacking EBS API's using BPEL

We are performing multiple activities in sequence( updating a database using database adapter , calling a Oracle EBS API using oracle applications adapter and inserting data in a queue using JMS adapter or AQ adapter etc.) Now our requirement is to roll back all the activities if any of the above mentioned activity fails.Solution: To achieve this we need to configure our BPEL process for JCA-XA transactions. This is requires following set up:

1. Set up JNDI name in oc4j-ra.xml and datasources.xml2. Make Changes in BPEL.xml to make your bpel to participate in transaction.For this we need to set the property transaction of BPEL and all partner links to participate as shown below.


<>
< id="TestTransaction2" src="TestTransaction2.bpel">
<>< name="client">
< name="wsdlLocation">TestTransaction2.wsdl

< name="TestAccount">
< name="wsdlLocation">TestAccount.wsdl
< /property>
< name="retryInterval">60< /property>
< name="transaction">participate< /property>
< /partnerLinkBinding>
< name="TestLocation">
< name="wsdlLocation">TestLocation.wsdl< /property>
< name="retryInterval">60< /property>
< name="transaction">participate< /property>
< /partnerLinkBinding>
< name="OA_Rollback">
< name="wsdlLocation">OA_Rollback.wsdl< /property>
< name="retryInterval">60< /property>
participate< /property>
< /partnerLinkBinding>
< /partnerLinkBindings>
<>
< faultpolicy="TestConditionPolicy">
< /faultPolicyBindings>
<>< name="transaction" encryption="plaintext">participate< /property>
< /configurations>
< /BPELPr>

Here we need to make sure that fault policy applied to BPEL is not sending your BPEL to manual intervention. Because while sending the BPEL on manual intervention all the activities gets committed so rollback will not be possible in that case.
Once above setup is done we are good to go. Now we have two possibilities:

1. BPEL is not configured to catch the faults thrown.
2. BPEL is configured to catch the faults thrown.

BPEL is not configured to catch the fault thrown:In this case as soon as the fault is thrown , all the activities automatically gets rolled back.
Disadvantage: Here the disadvantage is all the activities which are part of the transaction will get rolled back and we will not be able to see anything on BPEL console. It will appear that BPEL instance was never created.
BPEL is configured to catch the faults thrown
In this we have to explicitly call the rollback. This can be done in two ways:

1. Explicitly throwing the bpelx:rollbackFault
< name="Throw_1" faultname="bpelx:rollback">
Once the error is caught by the fault handler we can do the activities we want to and after that we can throw the rollback fault which will result in to the rollback of all activities part of the rolled back transaction.
In this case also disadvantage is we will not be able to see anything on BPELCONSOLE.

2. Calling a procedure containing the rollback statement.
This procedure will look like following
PROCEDURE "XXDPI_ROLLBACK" AS
BEGIN
rollback;
END;
Now once the error is caught you can explicitly call this procedure to cause the rollback of statements executed on a particular database. So if there are multiple databases, you will have to multiple such procedures.

Advantage: Advantage of this approach is that your BPEL instance still remains there and u can easily see what has actually happened and all the database statements executed also gets roll backed.

No comments: