How do I hold a jms message in queue until it is saved?

Tag: jms , weblogic-10.x Author: youhangf60801 Date: 2012-12-03

I just started using Weblogic JMS. I was able to send messages to the queue and pull them off with a messagebean. Now I want to save the message to a database.

So my question is, how do I tell JMS not to delete the message from the queue until I have successfully written the message to the database?

Thanks

Other Answer1

I was able to send messages to the queue and pull them off with a messagebean.

I suppose you are talking about message-driven bean (MDB)?

So my question is, how do I tell JMS not to delete the message from the queue until I have successfully written the message to the database?

MDBs are part of implicit container-managed transaction and the message will not be removed as long as your transaction hasn't commited (that is, as long as your onMessage method hasn't reached its end).

In case of rollback (i.e. you throw an exception or call context.setRollbackOnly() on the MessageDrivenContext), message will be redelivered. You can avoid this behaviour by making transaction bean-managed or using @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED), but in your situation that should not be the case. Stick with default configuration and everything should work as you wish.