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 » Multiphase Commit » :help: using transaction in mq series

Post new topic  Reply to topic
 :help: using transaction in mq series « View previous topic :: View next topic » 
Author Message
rashfmnb
PostPosted: Fri Jan 18, 2008 2:31 am    Post subject: :help: using transaction in mq series Reply with quote

Newbie

Joined: 18 Jan 2008
Posts: 4

Hi,



can any one please help me by sending the sample code which uses the System.Transactions while reading and writing the message from the MQ queue i have already use the simple transaction scope but it didn''t work well for me i will be grateful if some one help me regarding this matter

thanx

tc
and
AH
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Fri Jan 18, 2008 4:15 am    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20696
Location: LI,NY

Environment and OS please?
Version of MQ? Client or Server install?
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
rashfmnb
PostPosted: Tue Jan 22, 2008 4:45 am    Post subject: Reply with quote

Newbie

Joined: 18 Jan 2008
Posts: 4

The Environment is as follows:
- MQ Server 6.0 for Windows is installed on Windows 2003 Server on Machine1.
- MQ Client 6.0 for Windows is installed on Windows 2003 Server on Machine2.
- C# Program is running on Machine2.

When i am trying to read a message from the queue it reads it and after reading when i use the statment "throw new ArgumnetException()" in order to rollback the MTS transaction, it throws the exception but message which is read from the queue gets disappeared and does not get put back to the queue.


The objective is to read and write messages from MQ Server under MTS transactions. Please advise if you have some solution, preferably some code example with environment configuration settings.


public string ReadMsg()
{
MQQueueManager queueManager;
MQQueue queue;
MQMessage queueMessage;
MQPutMessageOptions queuePutMessageOptions;
MQGetMessageOptions queueGetMessageOptions;

static string QueueName;
static string QueueManagerName;
static string ChannelInfo;
string channelName;
string transportType;
string connectionName;
string message;
TransactionOptions to = new TransactionOptions();
to.IsolationLevel = IsolationLevel.Serializable;
to.Timeout = TransactionManager.DefaultTimeout;
TransactionScope oTS;
String strReturn = "";
try
{
using (oTS = new TransactionScope(TransactionScopeOption.Required,to,EnterpriseServicesInteropOption.Full))
{
//queueManager.Begin();
queue = queueManager.AccessQueue(QueueName, MQC.MQOO_INPUT_AS_Q_DEF + MQC.MQOO_FAIL_IF_QUIESCING + MQC.MQOO_INQUIRE);
//System.Windows.Forms.MessageBox.Show(queue.CurrentDepth.ToString());
queueMessage = new MQMessage();
queueMessage.Format = MQC.MQFMT_STRING;
queueGetMessageOptions = new MQGetMessageOptions();

queue.Get(queueMessage, queueGetMessageOptions);
//throw new Exception();
//queueManager.Commit();
strReturn = queueMessage.ReadString(queueMessage.MessageLength);
//System.Windows.Forms.MessageBox.Show(queue.CurrentDepth.ToString());

throw new Exception();
oTS.Complete();
}


}

catch (MQException MQexp)
{
strReturn = "Exception : " + MQexp.Message;
}

catch (Exception exp)
{
strReturn = "Exception: " + exp.Message;
}
return strReturn;
}



Regards


Last edited by rashfmnb on Tue Jan 22, 2008 4:47 am; edited 1 time in total
Back to top
View user's profile Send private message
rashfmnb
PostPosted: Tue Jan 22, 2008 4:46 am    Post subject: Reply with quote

Newbie

Joined: 18 Jan 2008
Posts: 4

The Environment is as follows:
- MQ Server 6.0 for Windows is installed on Windows 2003 Server on Machine1.
- MQ Client 6.0 for Windows is installed on Windows 2003 Server on Machine2.
- C# Program is running on Machine2.

When i am trying to read a message from the queue it reads it and after reading when i use the statment "throw new ArgumnetException()" in order to rollback the MTS transaction, it throws the exception but message which is read from the queue gets disappeared and does not get put back to the queue.


The objective is to read and write messages from MQ Server under MTS transactions. Please advise if you have some solution, preferably some code example with environment configuration settings.


The source code is as follows:

public string ReadMsg()
{
MQQueueManager queueManager;
MQQueue queue;
MQMessage queueMessage;
MQPutMessageOptions queuePutMessageOptions;
MQGetMessageOptions queueGetMessageOptions;

static string QueueName;
static string QueueManagerName;
static string ChannelInfo;
string channelName;
string transportType;
string connectionName;
string message;
TransactionOptions to = new TransactionOptions();
to.IsolationLevel = IsolationLevel.Serializable;
to.Timeout = TransactionManager.DefaultTimeout;
TransactionScope oTS;
String strReturn = "";
try
{
using (oTS = new TransactionScope(TransactionScopeOption.Required,to,EnterpriseServicesInteropOption.Full))
{
//queueManager.Begin();
queue = queueManager.AccessQueue(QueueName, MQC.MQOO_INPUT_AS_Q_DEF + MQC.MQOO_FAIL_IF_QUIESCING + MQC.MQOO_INQUIRE);
//System.Windows.Forms.MessageBox.Show(queue.CurrentDepth.ToString());
queueMessage = new MQMessage();
queueMessage.Format = MQC.MQFMT_STRING;
queueGetMessageOptions = new MQGetMessageOptions();

queue.Get(queueMessage, queueGetMessageOptions);
//throw new Exception();
//queueManager.Commit();
strReturn = queueMessage.ReadString(queueMessage.MessageLength);
//System.Windows.Forms.MessageBox.Show(queue.CurrentDepth.ToString());

throw new Exception();
oTS.Complete();
}


}

catch (MQException MQexp)
{
strReturn = "Exception : " + MQexp.Message;
}

catch (Exception exp)
{
strReturn = "Exception: " + exp.Message;
}
return strReturn;
}






Regards
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Tue Jan 22, 2008 4:57 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

I think you can't do this on a regular Client install.

I think you need Extended Transactional Client.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Tue Jan 22, 2008 4:57 am    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20696
Location: LI,NY

rashfmnb wrote:
The Environment is as follows:
- MQ Server 6.0 for Windows is installed on Windows 2003 Server on Machine1.
- MQ Client 6.0 for Windows is installed on Windows 2003 Server on Machine2.
- C# Program is running on Machine2.

And the manual says that this scenario does not enable multiphase commit on machine 2.
You need an MQServer on the machine you execute the C# program on to connect to for multiphase commit

For a single phase commit you are not using the SYNCPOINT option... so why would you expect it to happen?

Enjoy
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
rashfmnb
PostPosted: Tue Jan 22, 2008 6:03 am    Post subject: Reply with quote

Newbie

Joined: 18 Jan 2008
Posts: 4

What I understand is:

I should have an MQ Server on Machines1 that is acting as a queue manager.
On machine2 where I am running my C# program should have MQ Server instead of MQ Client. Then the 2 phase commit will work.

Please confirm my understanding.

Regards
Back to top
View user's profile Send private message
Vitor
PostPosted: Tue Jan 22, 2008 6:09 am    Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

rashfmnb wrote:
I should have an MQ Server on Machines1 that is acting as a queue manager.
On machine2 where I am running my C# program should have MQ Server instead of MQ Client. Then the 2 phase commit will work.


Yes (subject to the queue manager being configured to use the transaction coordinatior or be the transaction coordinator obviously).

The other option is to use the Extended Transactional Client mentioned earlier, but given how much it costs it's probably better / more useful to buy the additional server license for the 2nd machine.
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Tue Jan 22, 2008 6:24 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

No.

You need to either use a Bindings connection from your program, to the queue manager you want to coordinate a transaction with. This means running your program on Server1.

Or.

You need extended transactional client on Server2, and use that to create an XA connection to Server1.

Installing MQServer on Server2 won't help. It would allow you to do a two-phase commit with a new qmgr on Server2, but it won't help you do anything with the qmgr on Server 1.
_________________
I am *not* the model of the modern major general.
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 » Multiphase Commit » :help: using transaction in mq series
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.