Using transacted sessions in MQ

Hi,

I am trying to use transacted sessions in MQ. I create my session object like so

session = connection.createQueueSession(true, Session.AUTO_ACKNOWLEDGE);

I then send an object to the queue... By mistake the first time I did this I didn't use commit() on the session to actually send this message to the queue BUT to my surprise later on in the code when it trys to read the message back from the queue it was still successful!

WHY does the message get written to the queue if I don't commit()? Rollback() works and removes the message from the queue but what point is that if someone else can read it in the meantime!

Is there some way to begin a transaction that I have missed?

thanks

Will

[759 byte] By [willwright] at [2007-9-26 4:31:17]
# 1
I believe the default behavior is to commit if the end of the transaction is reached and no rollbacks occured.
swatdba at 2007-6-29 17:44:32 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2

Swatdba,

I agree that this appears to be what is happening but...

1) The MQ documentation for the session.close() method states

'Closing a transacted session rolls back any in-progress transaction.'

2) Does this mean that if the application goes wrong in the middle of writing a batch of messages then the messages will be sent anyway even if we don't reach the commit() statement - this seems VERY dangerous...

Will

willwright at 2007-6-29 17:44:32 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3

Hi Will,

I can't tell you how to avoid default commit. But I can show you how you can prevent others from reading messages you have'nt commited. You have to mention SYNCPOINT in the MQMessage put options class variable called options. for eg.

MQPutMessageOptions pmo = new MQPutMessageOptions();

pmo.options = MQC.MQPMO_SYNCPOINT;

The messages won't appear in case you have'nt commited them. In case you don't mention an explicit commit, he messages will be commited when you close the Queue.

I am also looking to find out how to avoid default commit in MQ. There must be some flag like in JDBC to do the same.

Hope this helps.

MB99 at 2007-6-29 17:44:32 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 4

> 1) The MQ documentation for the session.close() method

> states

> 'Closing a transacted session rolls back any

> in-progress transaction.'

BTW - This is also a necessary requirement for a JMS vendor.

Quoting JMS 1.1 specifications (Section 4.4.1 page 62)

" Closing a transacted session must roll back its transaction in progress."

- guneet

guneetsahai at 2007-6-29 17:44:32 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 5
I can only say that this definitely doesn't seem to be the case...
willwright at 2007-6-29 17:44:32 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 6
What MQ are you using and what's the JMS version it's built to?
jpfersich at 2007-6-29 17:44:32 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...