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.