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 » MQQueueManager disposal rollsback received messages

Post new topic  Reply to topic
 MQQueueManager disposal rollsback received messages « View previous topic :: View next topic » 
Author Message
costasz
PostPosted: Tue Nov 25, 2008 12:43 pm    Post subject: MQQueueManager disposal rollsback received messages Reply with quote

Novice

Joined: 26 Mar 2008
Posts: 18

Sample code
The 2nd line causes any received messages to reappear on queue
queueManager.Close();
}

The close bracket basically closes this using block

using (IBM.WMQ.MQQueueManager queueManager = new MQQueueManager(mqConnectionInfo.MqManager))
{

The using block disposes of the MQQueueManager. Can someone help with this?

Thanks




Full method:

private void doWork(MsmqToMqArg args)
{
try
{
using (System.Messaging.MessageQueue msmq = new System.Messaging.MessageQueue(args.MsmqConnection))
{
MQConnectionInfo mqConnectionInfo = new MQConnectionInfo(args.MqConnection);
MqHelper.SetEnvBasedOnConnection(mqConnectionInfo);
using (IBM.WMQ.MQQueueManager queueManager = new MQQueueManager(mqConnectionInfo.MqManager))
{
using (IBM.WMQ.MQQueue mqQueue = queueManager.AccessQueue(mqConnectionInfo.MqQueue, MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_FAIL_IF_QUIESCING))
{
while (!this.CancellationPending)
{
IBM.WMQ.MQMessage mqMessage = new MQMessage();
MQGetMessageOptions gmo = new MQGetMessageOptions();
gmo.Options = MQC.MQGMO_CONVERT + MQC.MQGMO_WAIT; //Wait until message arrives
if (args.Transactional)
{
gmo.Options += MQC.MQGMO_SYNCPOINT;
}
else
{
gmo.Options += MQC.MQGMO_NO_SYNCPOINT;
}
try
{
if (args.Transactional)
{
TransactionOptions options = new TransactionOptions();
options.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted;
options.Timeout = TransactionManager.DefaultTimeout;
using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, options, EnterpriseServicesInteropOption.Automatic))
{
mqQueue.Get(mqMessage, gmo);
if (mqMessage != null)
{
using (System.Diagnostics.EventLog eventLog = new System.Diagnostics.EventLog())
{
eventLog.Source = "MQ2MSMQBridge";
eventLog.WriteEntry("Picked up message", EventLogEntryType.Information);
}
System.Messaging.Message msmqMsg = new System.Messaging.Message();
MqHelper.CopyContents(mqMessage, msmqMsg);
msmq.Send(msmqMsg,MessageQueueTransactionType.Automatic);
// THROW EXCEPTION TO TEST ROLLBACK
/*
int y = 0;
int x = 10 / y;
*/
//
scope.Complete();

}
using (System.Diagnostics.EventLog eventLog = new System.Diagnostics.EventLog())
{
eventLog.Source = "MQ2MSMQBridge";
eventLog.WriteEntry("Sent message", EventLogEntryType.Information);
}
}
}

}
catch (IBM.WMQ.MQException mqex)
{
if (mqex.ReasonCode != 2033)
throw;
}
}
mqQueue.Close();
}
queueManager.Close();
}
msmq.Close();
}
}
catch (IBM.WMQ.MQException mqex)
{
using (System.Diagnostics.EventLog eventLog = new System.Diagnostics.EventLog())
{
eventLog.Source = "MQ2MSMQBridge";
eventLog.WriteEntry(mqex.Message + " - " + mqex.ReasonCode.ToString(),EventLogEntryType.Error);
}
}
catch (Exception ex)
{
using (System.Diagnostics.EventLog eventLog = new System.Diagnostics.EventLog())
{
eventLog.Source = "MQ2MSMQBridge";
eventLog.WriteEntry(ex.Message, EventLogEntryType.Error);
}
}
}
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Wed Nov 26, 2008 2:59 pm    Post subject: Reply with quote

Grand High Poobah

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

So it looks you are relying on an implicit commit here.
Is there a way to have your session explicitly force the commit of all resources?

Relying on a default behavior is never good as it may vary from platform to platform. I prefer to explicitly roll back or commit my transaction, even if it is to catch the exception on the commit and call rollback right after.


Have fun.
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
costasz
PostPosted: Fri Nov 28, 2008 6:27 am    Post subject: scope.Complete() is an explicit commit thru DTC. Reply with quote

Novice

Joined: 26 Mar 2008
Posts: 18

BTW, I found the issue. I needed to call MQQueueManager.Disconnect();
before it went out of scope and got garbage collected. Sounds like a bug to me.
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Fri Nov 28, 2008 6:38 am    Post subject: Re: scope.Complete() is an explicit commit thru DTC. Reply with quote

Grand High Poobah

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

costasz wrote:
BTW, I found the issue. I needed to call MQQueueManager.Disconnect();
before it went out of scope and got garbage collected. Sounds like a bug to me.

Sounds like a programing error to me.

Typically it is a very bad practice for resources (and a qmgr is considered a resource) to get closed at garbage collection and even worse for it to be out of scope at that time.

Best practice says: When your resource is no longer used you need to release it. Releasing it only at finalization / garbage collection time is very wasteful and can cause a number of problems.

Have fun
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
Vitor
PostPosted: Fri Nov 28, 2008 6:57 am    Post subject: Re: scope.Complete() is an explicit commit thru DTC. Reply with quote

Grand High Poobah

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

costasz wrote:
I needed to call MQQueueManager.Disconnect();
before it went out of scope and got garbage collected.


You sound surprised. Of course you need to disconnect from the queue manager. If you don't it looks to the queue manager like your application's abended and it performs a rollback.
_________________
Honesty is the best policy.
Insanity is the best defence.
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 » MQQueueManager disposal rollsback received messages
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.