JMS rollback

老子叫甜甜 提交于 2019-12-03 12:46:48

You can use JMS and JTA (Java Transaction API) together - see here. When doing that, the sending of a JMS message or the consumption of a received message actually happens atomically as part of the transaction commit.

What does this mean? If the transaction fails or is rolled back, the "sent" message doesn't go out and any "received" messages aren't really consumed. All handled for you by your JMS and JTA provider.

You need to be using a JMS implementation that supports JTA. Sounds like you're already using transactions, so it might be a matter of doing some configuration to make it happen (waving hand vigorously...).

I've had experience using this (BEA WebLogic 7 w/ BEA WebLogic Integration). Worked as advertised -- "the outside world" saw no impact of JMS stuff I tried unless the transaction committed successfully.

Karl

What you have described is an XA transaction. This allows a transaction to scope across multiple layers i.e. JMS provider, DB or any other EIS. Most containers can be configured to use both non XA and none XA transaction so check your container settings!

For example if you are using JMS with XA transactions the following is possible.

Start Transaction
      |
   DB Insert
      |
   Send JMS Msg
      |
   More DB Inserts
      | 
   Commit Transaction  <- Only at this point will the database records be inserted and the JMS message sent.

XA Tranactions are only available in full Java EE containers so XA transactions are not available in Tomcat.

Good luck!

Karl

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!