|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
help on UOW |
« View previous topic :: View next topic » |
Author |
Message
|
adder |
Posted: Wed Mar 01, 2006 6:25 pm Post subject: help on UOW |
|
|
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 |
|
 |
wschutz |
Posted: Wed Mar 01, 2006 6:30 pm Post subject: |
|
|
 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 |
|
 |
mvic |
Posted: Wed Mar 01, 2006 6:36 pm Post subject: Re: help on UOW |
|
|
 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 |
|
 |
mvic |
Posted: Wed Mar 01, 2006 6:41 pm Post subject: Re: help on UOW |
|
|
 Jedi
Joined: 09 Mar 2004 Posts: 2080
|
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 |
|
 |
adder |
Posted: Wed Mar 01, 2006 7:02 pm Post subject: |
|
|
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 |
|
 |
wschutz |
Posted: Wed Mar 01, 2006 7:06 pm Post subject: |
|
|
 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 |
|
 |
adder |
Posted: Wed Mar 01, 2006 7:33 pm Post subject: |
|
|
Apprentice
Joined: 06 Dec 2005 Posts: 43
|
another question:
can MQ support more than one queue manager involoved into one UOW? |
|
Back to top |
|
 |
|
|
 |
|
Page 1 of 1 |
|
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
|
|
|
|