|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
MQQueueManager rolls back on dispose |
« View previous topic :: View next topic » |
Author |
Message
|
costasz |
Posted: Wed Nov 26, 2008 12:15 pm Post subject: MQQueueManager rolls back on dispose |
|
|
Novice
Joined: 26 Mar 2008 Posts: 18
|
Sorry for the double post, this post got no attention on the multiphase commit forum.
To summarize, when disposed, the MQQueueManager rollsback transactions that were previously completed using scope.Complete();
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 |
|
 |
PeterPotkay |
Posted: Wed Nov 26, 2008 2:24 pm Post subject: |
|
|
 Poobah
Joined: 15 May 2001 Posts: 7722
|
Please don't double post. The same people that care enough to answer care enough to read all the forums here. _________________ Peter Potkay
Keep Calm and MQ On |
|
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
|
|
|
|