• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JMS and JDBC In a single transaction

 
Gagan Tiwari
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I am having an application which is Spring based. (With no application or web server)

Now I need to read the records from the Database Table (Oracle) and put the message on the Queue (MQ).
But since these are two diffrent activity, how can we gurantee the Treansaction?

Please provide a way for this.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34202
341
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Normally, one uses an XA driver to include the two operations - database and queue writing. I've never used one outside an application server, but it seems like it should be allowed.
 
Gagan Tiwari
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Can you please provide an example (Sample Code) for the same?
 
kri shan
Ranch Hand
Posts: 1462
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How XA driver commits two operations separately ?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34202
341
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gagan,
An example of hwat? Creating an XA driver in the spring config? Something else?

Kri,
The driver "polls" each resource to see if it is ready to commit.
 
Gagan Tiwari
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the prompt response.

By example I meant sample code using Spring to have a JMS Operation and the JDBC in a single transaction.

I have searched a lot but unable to find the same.
Also in many post (On the Web) I have read that using Spring JTA transaction is not so god approach.
Kindly suggest
 
kri shan
Ranch Hand
Posts: 1462
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The driver "polls" each resource to see if it is ready to commit.

Hi Jeanne, Whether driver "polls" each resource by transaction manager? If 1st JDBC transaction succeds, but 2nd JMS transaction fails, how it rollback both the transaction ?
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Two Phase Commit

I believe you have to have an XA-aware JDBC driver to use XA - so I'd assume the driver would internally be able to do the rollback.
 
kri shan
Ranch Hand
Posts: 1462
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whether we have to commit individually each transaction (or) single 'commit' commits both the transaction ?
 
Prabhakar Reddy Bokka
Ranch Hand
Posts: 197
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hope there will not be 2 commits in this case.

Data fetched from Database,
Put the message into MQ
On successful response from MQ Commit Database.

That completes the total transaction successfully.

This can be done using UserTransaction normally in web applications, So we can do that in Spring also.

Look at the link webpage

If yours is a standalone java application...

Set your auto commit false,
Fetch the data from database,
send the message to MQ,
after successful response from MQ, commit database.
 
kri shan
Ranch Hand
Posts: 1462
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If data is fetched from database1 and data is updated to database2, Whether we need separate commmit for each database transaction?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic