ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » IBM MQ Java / JMS » Is there a way to rollback a recieved message?

Post new topic  Reply to topic
 Is there a way to rollback a recieved message? « View previous topic :: View next topic » 
Author Message
smalltalk2k
PostPosted: Mon May 16, 2005 5:07 am    Post subject: Is there a way to rollback a recieved message? Reply with quote

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
View user's profile Send private message
jefflowrey
PostPosted: Mon May 16, 2005 5:16 am    Post subject: Reply with quote

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
View user's profile Send private message
dwitherspoon
PostPosted: Tue May 24, 2005 12:15 pm    Post subject: Simple... Reply with quote

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
View user's profile Send private message
fjb_saper
PostPosted: Tue May 24, 2005 12:22 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
dwitherspoon
PostPosted: Tue May 24, 2005 12:25 pm    Post subject: Good catch! Reply with quote

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
View user's profile Send private message
smalltalk2k
PostPosted: Wed Jun 01, 2005 5:16 am    Post subject: Reply with quote

Novice

Joined: 03 May 2005
Posts: 10

I figured out how to do transactional jms. the code i used is in the following post.

http://www.mqseries.net/phpBB2/viewtopic.php?p=96895#96895
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » IBM MQ Java / JMS » Is there a way to rollback a recieved message?
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.