Author |
Message
|
smalltalk2k |
Posted: Mon May 16, 2005 5:07 am Post subject: Is there a way to rollback a recieved message? |
|
|
Novice
Joined: 03 May 2005 Posts: 10
|
Is there a way to roll back the reception of a message so that it isn't taken of fthe queue.
My situation...
Code: |
qcf = (QueueConnectionFactory) context.lookup(Messages.getString("JMS_TEST7.SERVER_NAME")); //$NON-NLS-1$
// Create a new queue connection from the queue
// connection factory.
conn = qcf.createQueueConnection();
// Create a new queue session from the queue
// connection. The session should not be transacted
// and should use automatic message acknowledgement.
session = conn.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
// Lookup the queue to be used to send and receive
// messages from the initial context.
q = (Queue) context.lookup(Messages.getString("JMS_TEST7.QUEUE_NAME")); //$NON-NLS-1$
// Create a new queue receiver using the queue session.
// The queue receiver should be created to receive
// messages from the queue q.
receiver = session.createReceiver(q);
// Start the connection
conn.start();
log.debug(Messages.getString("JMS_TEST7.MESSAGE_CONNECTED")); //$NON-NLS-1$
while (isRunning()) {
Message m = receiver.receive(1);
.... process the message
} |
In the 'process the message' I update some database tables with data from the message. If some error occurs like a database failure or something. Is there a way to roll back the message so it goes back to the queue. |
|
Back to top |
|
 |
jefflowrey |
Posted: Mon May 16, 2005 5:16 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
Yes.
A lot of the java sample code will show you how. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
dwitherspoon |
Posted: Tue May 24, 2005 12:15 pm Post subject: Simple... |
|
|
 Acolyte
Joined: 09 Dec 2003 Posts: 59
|
My code sounds much like yours. I want to make sure the message gets processed correctly and the db updated. If anything goes wrong on either side, I want to roll the message back onto the queue and try again.
So I bring all my work to a single point where I do a commit on the db and then a commit on MQ. If the db commit fails, then I catch that exception and call backout on the queue manager.
Note that if the db commit works, but the mq commit fails, then MQ will roll the message back for you and then you'll see it again...suggesting that you have to be able to cope with duplicate messages.
The way around that is to get into XA, which is true two-phase commit. Doing what I mentioned above is what I call "two-faced commit". Face one provider and commit, face the other and commit, and then cope with the consequences. _________________ Good...Fast...Cheap. Choose any two. |
|
Back to top |
|
 |
fjb_saper |
Posted: Tue May 24, 2005 12:22 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
check out the meaning of the difference in this line of code
Code: |
session = conn.createQueueSession(true, Session.AUTO_ACKNOWLEDGE); |
Enjoy  |
|
Back to top |
|
 |
dwitherspoon |
Posted: Tue May 24, 2005 12:25 pm Post subject: Good catch! |
|
|
 Acolyte
Joined: 09 Dec 2003 Posts: 59
|
Ahh...good catch. I didn't notice that. Yep...with autoack you never get a crack at it. _________________ Good...Fast...Cheap. Choose any two. |
|
Back to top |
|
 |
smalltalk2k |
Posted: Wed Jun 01, 2005 5:16 am Post subject: |
|
|
Novice
Joined: 03 May 2005 Posts: 10
|
|
Back to top |
|
 |
|