Reputation: 7549
I find the similar question here but didn't find a clear answer on the transaction management for back end (database)
My current project is to create producer/consumer and let consumer to digest JMS message and persist in database. Because the back end of the application is managed by JPA
, so it is critical to maintain the whole process transactional. My question is what is the downside if place @Transactional
annotation on the classic onMessage
method? Is there any potential performance challenge if do so?
Upvotes: 1
Views: 682
Reputation: 85779
The only problem may be if the whole queue process takes too long and the connection closes in the middle of the operation. Apart of this, if you enable the transaction for the whole queue process rather than per specific services methods, then theoretically the performance should be the same.
It would be better to enable two phase commit (also known as XA transaction) for each queue process. Then, define each specific service method as @Transactional
and interact with your database as expected. At the end, the XA transaction will perform all the commits done by the @Transactional
service methods. Note that using this approach does affect your performance.
Upvotes: 1