|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
problem in single phase commit |
« View previous topic :: View next topic » |
Author |
Message
|
vivekkooks |
Posted: Sat Jul 26, 2003 12:02 am Post subject: problem in single phase commit |
|
|
 Voyager
Joined: 11 Jun 2003 Posts: 91
|
Hello ,
I have installed MQSeries on Linux/Intel.
I have tested the single phase commit mechanish using the sample mqsync.cpp. It is working fine.
( this sample puts the message to queue. if commited the operation, the message will be available to other applications. if backout , message will be removed from queue)
But when I want to test it for get message call (get the message, if commit the message , then message will be removed from the queue, else message will be restored back), the message is removed irrespective of commit or backout.
The program code is as follows:
ImqQueueManager qmgr;
ImqQueue queue;
ImqMessage msg;
ImqPutMessageOptions gmo;
qmgr.setName( "testMQM")
qmgr.connect( ) // getting connected successfully
queue.setConnectionReference( qmgr );
queue.setName( "TESTQUEUE");
queue.setOpenOptions( MQOO_INPUT_AS_Q_DEF| +
MQOO_FAIL_IF_QUIESCING
);
msg.useEmptyBuffer(buffer, sizeof(buffer));
msg.setFormat(MQFMT_STRING);
gmo.setSyncPointParticipation(TRUE);
queue.get(msg, gmo)
qmgr.backout();
// message is still removed from queue.
Can anybody please help me in this regard? |
|
Back to top |
|
 |
bower5932 |
Posted: Tue Jul 29, 2003 11:48 am Post subject: |
|
|
 Jedi Knight
Joined: 27 Aug 2001 Posts: 3023 Location: Dallas, TX, USA
|
I just tried this and it worked for me. However, I did run into one gotcha (ie, coding error on my part). When I issue the backout, the message is put back onto the queue and it is then picked up by the next get in syncpoint. I ended up draining the queue so it appeared that things weren't working. |
|
Back to top |
|
 |
vivekkooks |
Posted: Wed Jul 30, 2003 12:31 am Post subject: |
|
|
 Voyager
Joined: 11 Jun 2003 Posts: 91
|
It is not working on my side. i.e. even I am backing out the message, it is getting removed from the queue.(i.e. it is not available for next get)...
Any clues? |
|
Back to top |
|
 |
bower5932 |
Posted: Wed Jul 30, 2003 6:39 am Post subject: |
|
|
 Jedi Knight
Joined: 27 Aug 2001 Posts: 3023 Location: Dallas, TX, USA
|
I'll put my program at the bottom of this append. I run my program, and I enter in "sync back". This does the get in syncpoint and then backs it out. If I run amqsget afterwards, it will find the message that the program backed out.
Code: |
#include <stdlib.h>
#include <string.h>
#include <iostream.h>
#include <imqi.hpp>
const int MAX_BUFF_SIZE = 100;
int main(int argc, char **argv) {
ImqQueueManager qmgr;
ImqQueue queue;
ImqMessage msg;
ImqGetMessageOptions gmo;
int bSyncPoint = 0; /* indicator if messages are in syncpoint */
MQLONG buflen; /* buffer length */
char buffer[MAX_BUFF_SIZE];
char inBuffer[MAX_BUFF_SIZE];
cout << "Sample mqsync C++ start" << endl;
if (argc < 2) {
cout << "Required parameter missing - queue name" << endl;
exit(99);
} else {
cout << " Use SYNC or sync in message text for syncpoint'ed message"
<< endl
<< " Use CMIT or cmit in message text to commit messages"
<< endl
<< " Use BACK or back in message text to backout (discard) messages"
<< endl;
}
/***************************************************************/
/* 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_INPUT_AS_Q_DEF | 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) - 1);
msg.setFormat(MQFMT_STRING);
/****************************************************************/
/* Read lines from the user and put them to the message queue */
/* Loop until null line or there is a failure */
/****************************************************************/
gmo.setOptions(MQGMO_WAIT);
gmo.setWaitInterval(15000);
cout << "type of get?";
cin.getline(inBuffer, MAX_BUFF_SIZE);
buflen = strlen(buffer);
/****************************************************************/
/* If we got a buffer, put it to the message queue. */
/****************************************************************/
if (buflen > 0) {
msg.setMessageId();
msg.setCorrelationId();
/***************************************************************/
/* See if the message text contains SYNC or sync. If it does, */
/* turn the pmo syncpoint option to on. */
/***************************************************************/
if ( strstr(inBuffer, "SYNC")
|| strstr(inBuffer, "sync")) {
gmo.setSyncPointParticipation(TRUE);
bSyncPoint = 1;
} else {
gmo.setSyncPointParticipation(FALSE);
}
if (!queue.get(msg, gmo)) {
cout << "ImqQueue::get ended with reason code "
<< queue.reasonCode( ) << endl;
} else {
buffer [msg.dataLength()] = 0;
cout << " msg: " << msg.bufferPointer() << endl;
/*************************************************************/
/* See if the message text indicates to back out or commit */
/* the syncpointed messages. The message has already been */
/* put on the message queue. */
/*************************************************************/
if ( strstr(inBuffer, "BACK")
|| strstr(inBuffer, "back") ) {
bSyncPoint = 0;
if (!qmgr.backout()) {
cout << "ImqQueueManager::backout ended with reason code "
<< qmgr.reasonCode( ) << endl;
} else {
cout << " backout performed" << endl;
}
} else if ( strstr(inBuffer, "CMIT")
|| strstr(inBuffer, "cmit") ) {
bSyncPoint = 0;
if (!qmgr.commit()) {
cout << "ImqQueueManager::commit ended with reason code "
<< qmgr.reasonCode( ) << endl;
} else {
cout << " commit performed" << endl;
}
}
}
}
/**************************************************************/
/* If the flag that indicates there are messages in syncpoint */
/* is turned on, then commit the messages before exiting. */
/**************************************************************/
if (bSyncPoint) {
cout << "Syncpoint not done in loop, performing now" << endl;
if (!qmgr.commit()) {
cout << "ImqQueueManager::commit ended with reason code "
<< qmgr.reasonCode( ) << endl;
}
} /* endif */
/****************************************************************/
/* Close the target queue */
/****************************************************************/
if ( !queue.close()) {
cout << "ImqQueue::close ended with reason code "
<< queue.reasonCode( ) << endl;
}
/****************************************************************/
/* Disconnect from queue manager */
/****************************************************************/
if (!qmgr.disconnect()) {
cout << "ImqQueueManager::disconnect ended with reason code "
<< qmgr.reasonCode( ) << endl;
}
/******************************************************************/
/* End of MQSYNC.CPP */
/******************************************************************/
cout << "Sample mqsync C++ end" << endl;
return(0);
}
|
|
|
Back to top |
|
 |
vivekkooks |
Posted: Wed Jul 30, 2003 1:52 pm Post subject: |
|
|
 Voyager
Joined: 11 Jun 2003 Posts: 91
|
It worked!!!!.
In my code I was calling
gmo.setSyncPointParticipation(TRUE) before
gmo.setOptions(MQGMO_WAIT) ;
gmo.setWaitInterval(15000);
queue.get(msg,gmo);
instead of :
gmo.setOptions(MQGMO_WAIT) ;
gmo.setWaitInterval(15000);
gmo.setSyncPointParticipation(TRUE)
queue.put(msg,gmo);
But I think the sequence should not matter.... Is it a bug in MQSeries c++ code? |
|
Back to top |
|
 |
bower5932 |
Posted: Wed Jul 30, 2003 2:04 pm Post subject: |
|
|
 Jedi Knight
Joined: 27 Aug 2001 Posts: 3023 Location: Dallas, TX, USA
|
I just checked out the C++ manual. It turns out that the behavior that you are seeing is documented. The setOptions sets all of the GMO options. By putting it after the syncPoint, you turn off the syncpoint.
The manual:
Quote: |
void setOptions (const MQLONG options);
Sets the options, including the syncpoint participation value.
|
|
|
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
|
|
|
|