Hi All,
Retrying and rolling back transactions that got failed while invocation is one of the major things that needs to be keep in mind while designing the solution for any interface.As it helps in preventing any data discrepancy that can be there between source and target systems,had there not been any rollback in case of failed transaction.
I will be demonstrating,how to retry and rollback failed transactions in SOA.To illustrate this use case I will be using one JMS queue from where our composite will consume the message and, after that it will insert data in 3 tables that I have created for this usecase.you will be requiring XA JNDIs both for Database and JMS Adapters.
Three tables have been created namely Customer,Order, and Invoice.Our SOA process will insert records in table in the same order.
On weblogic console,we need to set some properties for our jms queue for retry functionality.Just go to your jms queue and navigate to "Delivery Failure" tab for your queue.Set following parameters
NOTE: Any fault thrown using throw activity that is not being caught will result in rollback of complete transaction.
Now,first we will test the happy path.Deploy your code to EM and test the interface.Records will be inserted into all the tables successfully.
To see how rollback works,I will intentionally change the DB jndi for Invoice adapter.To do that open jca file for your Invoice DB Adapter and give some random value in that.Save and redeploy the code.Now the interface will fail while inserting the data in Invoice table and flow will got to Catch All block,where transaction will be rollbacked.
To validate this,check the tables and no new records would have been inserted into the tables.
Since we have configured,retry parameters for our request queue, the rollbacked message will be retried again after 10 seconds.Message state will be changed to "delayed" which means it is being retried.
After all failed attempts the message will be redirected into the error destination that we have configured for our queue.
In this way, you can implement retry and rollback functionality in your interfaces.
Hope this helps you.
Happy Learning,
Cheers !!!
Retrying and rolling back transactions that got failed while invocation is one of the major things that needs to be keep in mind while designing the solution for any interface.As it helps in preventing any data discrepancy that can be there between source and target systems,had there not been any rollback in case of failed transaction.
I will be demonstrating,how to retry and rollback failed transactions in SOA.To illustrate this use case I will be using one JMS queue from where our composite will consume the message and, after that it will insert data in 3 tables that I have created for this usecase.you will be requiring XA JNDIs both for Database and JMS Adapters.
Three tables have been created namely Customer,Order, and Invoice.Our SOA process will insert records in table in the same order.
On weblogic console,we need to set some properties for our jms queue for retry functionality.Just go to your jms queue and navigate to "Delivery Failure" tab for your queue.Set following parameters
- Redilvery Delay Override: 10000 (10 seconds) It is the interval after which rolledback messages will be retried.
- Redilvery Limit: 2 (Number of times failed message will be retried).
- Expiration Policy: Redirect (or Discard, if you want to discard the message after retry) Redirect will move the message to "Error Destination" if even after configured retry parameters message is failed.
- Error Destination: <Queue Name> Queue to which failed message will be moved after all retry attempts.
NOTE: Any fault thrown using throw activity that is not being caught will result in rollback of complete transaction.
Now,first we will test the happy path.Deploy your code to EM and test the interface.Records will be inserted into all the tables successfully.
To see how rollback works,I will intentionally change the DB jndi for Invoice adapter.To do that open jca file for your Invoice DB Adapter and give some random value in that.Save and redeploy the code.Now the interface will fail while inserting the data in Invoice table and flow will got to Catch All block,where transaction will be rollbacked.
To validate this,check the tables and no new records would have been inserted into the tables.
Since we have configured,retry parameters for our request queue, the rollbacked message will be retried again after 10 seconds.Message state will be changed to "delayed" which means it is being retried.
After all failed attempts the message will be redirected into the error destination that we have configured for our queue.
In this way, you can implement retry and rollback functionality in your interfaces.
Hope this helps you.
Happy Learning,
Cheers !!!
Hi,I have the same scenario where I am reading from a JMS queue and writing into DB table but I am getting the error " Caused by java.sql.SQLException: Cannot call Connection.commit in distributed transaction".
ReplyDeletePlease help how can I resolve this
Can u pls tell wen r u getting this exception ?? while writing into DB or while rolling back in case of failure ??
DeleteHi Karan,
DeleteThe above eror get resolved.My DS was xa but i was giving it into nonxa DS in DB connection pool.Now my success case is working fine but retry is still not working.I gave wrong jndi for DB but still I can't see the transaction rollback.Once the message is picked from queue, its not going back to the queue.
Hi,
DeleteHave u added catch all activity ?? and in case of error, is your flow going into catch all block ?? In the catch all block have u thrwon rollback activity ?? Cross check your jms JNDI it should be XA as well
Please check and let me know.
Regards,
Karan
Hi Karan, I have added catch all activity only and my JNDI is also xa.and I have thrown rollback also as you have mentioned.
DeleteDo I need to make sync WSDL for JMS? As of now my all wsdls are async only.
It should rollback then....In the flow trace are you able to see transaction rollback message just after throw activity ?? one in the 3rd last screenshot
DeleteI hope all your jndis jms and DB are XA
Sep 5, 2013 6:44:09 AM The transaction was rolled back. The work performed for bpel instance "50102" was rolled back, but the audit trail has been saved for this instance.If this is a sync request, please resubmit the request from the client. If it is an async request, please recover from the recovery console by resubmitting the invoke message.
Fetching Data...
I am getting this message. I have verified all my jndi and DS ...all are XA only
Can you check and confirm whether the data you are inserting into tables, its getting rolledback in case of failure ??
DeleteNo, That is the issue, its not getting rolled back. I am loosing the messages once its picked up from jms.
ReplyDeleteSend me ur code on my mail id. I will try to figure out the issue.
ReplyDeleteThank you Karan. Very helpful blog.
ReplyDeleteExcellent Karan Mann..All your posts are superb.Lot of useful to me.Thank You so much.
ReplyDelete