Monday, March 24, 2014

Error handling in SOA JMS

The scenario is as below

JMS---->SOA--->DB1---->DB2


A soa process is subscribing to a jms queue and then inserting the data in two table via two db call.

the requirement is that if transaction fails in DB2 the whole transaction should roll back and the message in queue should be redirected to error queue.


To achieve this first of all create two queue

TestQueue - This will be the queue from where soa process will subscribe the message and further insert data in to db.

RetryQueue- This will be the error queue where data will be moved once there is an issue in the BPEL process.


The additional configuration that needs to be done in case of TestQueue to redirect it to Retry queue is as below




This configuration ensure that the process will retry again at an interval of 1 millisecond and it fails the message will be redirected to the RetryQueue.

Now coming to SOA part.

Few things that needs to be taken care of while designing the BPEL process is

1> Make sure you are using XA transaction.

2> Only for Remote fault the retry can be done so we will have to explicitly capture all the error in the db call and send it as remote fault. We can also do a rollback in that case also the transaction will reach till the queue and the required functionality can be achieved.

so this is how now the process will look like.




In this case i have used a single scope and have captured the error . Again a throw activity has been used to throw a rollback exception so that process can start from the beginning and the message can go to error queue.





You can use an individual scope and capture the fault in each of the db call , In this case i just have used a single scope to present the idea.

Further this process will also work if we dont use a scope and if a remote fault comes in any of the db call however there are enough chances that one will get a binding fault which can not be retried hence i have wrapped the two adapters and have thrown a rollback fault.

No comments: