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 API Support » help on UOW

Post new topic  Reply to topic
 help on UOW « View previous topic :: View next topic » 
Author Message
adder
PostPosted: Wed Mar 01, 2006 6:25 pm    Post subject: help on UOW Reply with quote

Apprentice

Joined: 06 Dec 2005
Posts: 43

I write a sample code(c++) to learn UOW of MQ, in this sample
syncpoint does not used, I choose qmgr.begin() and qmgr.commit()
first put a message and call qmgr.commit()
second put a message and call qmgr.backout()
but these two message all put into queue when I use amqsget to check.
So I wanna know what's wrong, thanks!

Code:
#include <stdlib.h>
#include <string.h>

#include <iostream>
#include <imqi.hpp>

const int MAX_BUFF_SIZE = 100;
using namespace std;
int main(int argc, char **argv) {

   ImqQueueManager      qmgr;
   ImqQueue             queue;
   ImqMessage           msg;
   ImqPutMessageOptions pmo;

   int      bSyncPoint = 0;        /* indicator if messages are in syncpoint */
   MQLONG   buflen;                /* buffer length                 */
   char     buffer[MAX_BUFF_SIZE];

   cout << "Sample mqsync C++ start" << endl;
   if (argc < 2) {
      cout << "Required parameter missing - queue name" << endl;
      exit(99);
   }

   /***************************************************************/
   /* Connect to queue manager                                    */
   /***************************************************************/
   if (argc > 2) {
      qmgr.setName( argv[ 2 ] );
   }

   if ( !qmgr.connect( ) ) {
      cout << "ImqQueueManager::connect failed with reason code "
           << qmgr.reasonCode( ) << endl;
      exit(99);
   }

   /***************************************************************/
   /* Get the queue name that will be used and open it for output */
   /***************************************************************/
   queue.setConnectionReference( qmgr );
   queue.setName( argv[ 1 ] );
   queue.setOpenOptions( MQOO_OUTPUT | MQOO_INQUIRE );

   queue.open();

   /***************************************************************/
   /* If there was an error opening the queue, print it out.      */
   /***************************************************************/
   if (queue.reasonCode()) {
      cout << "ImqQueue::open ended with reason code "
           << queue.reasonCode( ) << endl;
   }

   if (queue.completionCode()) {
      cout << "Unable to open queue for output" << endl;
   }
   msg.useEmptyBuffer(buffer, sizeof(buffer));
   msg.setFormat(MQFMT_STRING);
   strcpy(buffer,"commit message");
   msg.setMessageLength(strlen(buffer));
   qmgr.begin();
    if (!queue.put(msg, pmo))
            cout << "ImqQueue::put ended with reason code "
                 << queue.reasonCode( ) << endl;
   qmgr.commit();
   
   memset(buffer,0,sizeof(buffer));
   strcpy(buffer,"backout message");
   msg.setMessageLength(strlen(buffer));
   qmgr.begin();
    if (!queue.put(msg, pmo))
            cout << "ImqQueue::put ended with reason code "
                 << queue.reasonCode( ) << endl;
   qmgr.backout();
   
   if ( !queue.close()) {
      cout << "ImqQueue::close ended with reason code "
           << queue.reasonCode( ) << endl;
   }

   if (!qmgr.disconnect()) {
      cout << "ImqQueueManager::disconnect ended with reason code "
           << qmgr.reasonCode( ) << endl;
   }
   
   cout << "Sample mqsync C++ end" << endl;
   return(0);
}
Back to top
View user's profile Send private message MSN Messenger
wschutz
PostPosted: Wed Mar 01, 2006 6:30 pm    Post subject: Reply with quote

Jedi Knight

Joined: 02 Jun 2005
Posts: 3316
Location: IBM (retired)

you need to specify MQPMO_SYNCPOINT when putting the messages, otherwise they are committed as soon as the put is called.
_________________
-wayne


Last edited by wschutz on Wed Mar 01, 2006 6:38 pm; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail AIM Address
mvic
PostPosted: Wed Mar 01, 2006 6:36 pm    Post subject: Re: help on UOW Reply with quote

Jedi

Joined: 09 Mar 2004
Posts: 2080

Wayne is quite right.

Also, you did not check the success of qmgr.begin(). In this scenario I think it will not succeed (qmgr.begin is MQBEGIN, which begins a distributed unit of work incorporating database updates - but I am guessing you don't have the necessary config for this in qm.ini).

Seeing that you are not performing any database updates, you probably aren't interested in using distributed units of work, and so qmgr.begin() is not relevant for this app anyway.
Back to top
View user's profile Send private message
mvic
PostPosted: Wed Mar 01, 2006 6:41 pm    Post subject: Re: help on UOW Reply with quote

Jedi

Joined: 09 Mar 2004
Posts: 2080

adder wrote:
Code:
   qmgr.commit();

Also it is very important to check the success of qmgr.commit(). UOWs can fail for a variety of reasons (most often if the system is in some difficulty - eg. getting short of disk space to log the transaction). Although this is rare, the integrity of your UOW is obviously important, so you must code to handle the failing commit.
Back to top
View user's profile Send private message
adder
PostPosted: Wed Mar 01, 2006 7:02 pm    Post subject: Reply with quote

Apprentice

Joined: 06 Dec 2005
Posts: 43

mvic,wschutz, thanks very much.

I am a fresh man for MQ. so for every message put into or get from MQ, syncpoint option need to be set in pmo or gmo, then these message can be in a UOW, right?

Code:
pmo.setSyncPointParticipation(TRUE);


and check stauts of commit
Code:
 if (!qmgr.commit()) {
                  cout << "ImqQueueManager::commit ended with reason code "
                       << qmgr.reasonCode( ) << endl;
Back to top
View user's profile Send private message MSN Messenger
wschutz
PostPosted: Wed Mar 01, 2006 7:06 pm    Post subject: Reply with quote

Jedi Knight

Joined: 02 Jun 2005
Posts: 3316
Location: IBM (retired)

Quote:
so for every message put into or get from MQ, syncpoint option need to be set in pmo or gmo, then these message can be in a UOW, right?
Yes, on windows,iSeries and unix qmgrs, the default is that the put or get of a message is immediately committed, so if you want the put/get to be part of a larger unit of work, you must specify gmp/pmo_syncpoint.
(by the way, the default on zOS is the opposite )
_________________
-wayne
Back to top
View user's profile Send private message Send e-mail AIM Address
adder
PostPosted: Wed Mar 01, 2006 7:33 pm    Post subject: Reply with quote

Apprentice

Joined: 06 Dec 2005
Posts: 43

another question:
can MQ support more than one queue manager involoved into one UOW?
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » IBM MQ API Support » help on UOW
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.