4

I have the strange phenomenon that jms messages seem to be sent before the database commit actually happened.

Lets say I have a server operation foo() which sends a message to the client when its completed. The client then loads the changed data from the server. It now appears that the jms message is sent before the commit is actually done, so the client still gets the old data, because its request is still before the end of the original commit.

The whole server operation is definately transactional, because if an exception is thrown, the jms event is not sent.

is there any requirement in the jms specification that first all database commits have to happen, and then the jms message is to send, or is it up to the implementation in which order this happens?

We are talking about the default hornetq implementation in jboss 6.0.0.Final.

Update:

It seems I have the same problem as these guys: http://techstack.com/forum/websphere/34434-order-commits-xa-transaction.html

Update 2:

Another user with the same problem http://community.jboss.org/message/114459

8
  • I didn't understand certain parts of your question. Can you please provide more context on how foo() is invoked? It does matter if this is occuring in an MDB, as opposed to any other code where no transactional requirements have been set. By the way, database commits are tangential to the sending of JMS messages; the sending depends on the presence of a transaction manager. Jun 10, 2011 at 13:04
  • the link makes it much clearer now. Can you check whether you are following the programming paradigm specified in this document? Although it is for JBoss 4, most of the points are relevant, especially that of having the DB transaction isolation level of READ_COMMITTED, and that of using the java:/JmsXA to locate the connection factory. Jun 10, 2011 at 13:26
  • @vineet-reynolds, Yes all transactional behaviour should be as it is supposed to be. I actually managed to shrink my problem to a very small example, I will see that I can update my question with it (it is still a bit unwieldy)
    – Mauli
    Jun 27, 2011 at 16:18
  • @Mauli Hi Mauli, I know its a very long time since this question was raise. But you managed to solve it?
    – Gandhi
    Jan 21, 2019 at 13:51
  • @Mauli Hi Mauli, Were you able to resolve this problem?
    – Gandhi
    Jan 22, 2019 at 11:29

2 Answers 2

1

You just need to make sure your Connection Factory is part of the same XA transaction.

you have to set REQUIRES_NEW on the EJB as Gursel Koca said in another post here.

The simpler will be you using the JCA Connection Factory (usually at java://JmsXA)

0

JMS operations are transactional, that is why jms message is delivered at commit time. If you want to see committed data, put db operations another EJB method with transactional property REQUIRES_NEW.

1
  • This is not what I want, the JMS Messages have to be in the same transaction. It just seems that the JMS messages are sent to early.
    – Mauli
    Jun 10, 2011 at 13:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.