IBM MQ Put inside .NET TransactionScope throws MQRC_NOT_AUTHORIZED

289 Views Asked by At

Any idea why the following minimal example throws MQRC_NOT_AUTHORIZED MQException with the following command line output?

Connecting to queue manager.. done
Accessing queue DEV.QUEUE.1.. done
Message .. 
MQException caught: 2035 - MQRC_NOT_AUTHORIZED
   at IBM.WMQ.MQDestination.Put(MQMessage message, MQPutMessageOptions pmo)
   at IBMMQTests.WMQTests.PutInsideTransactionScope() in WMQTests.cs:line 40

The example is adapted from IBM MQ .NET sample SimpleXAPut.cs (cf. https://www.ibm.com/support/knowledgecenter/SSFKSJ_7.5.0/com.ibm.mq.dev.doc/q029320_.html), and run with IBM MQ running as a container on localhost:

docker run --env LICENSE=accept --env MQ_QMGR_NAME=QM1 --publish 1414:1414 --publish 9443:9443 ibmcom/mq

This happens on both macOS (.NET Core) and on Windows (both .NET Core and .NET Framework) - using the IBM MQ .NET Standard client NuGet package: https://www.nuget.org/packages/IBMMQDotnetClient/

The transaction scope is necessary for coordinating transactions across multiple systems (i.e., database and message queue).

using System;
using System.Transactions;
using IBM.WMQ;
using NUnit.Framework;

namespace IBMMQTests
{
    public class WMQTests
    {
        [Test]
        public void PutInsideTransactionScope()
        {
            var connectionName = "localhost";
            var queueManagerName = "QM1";
            var channelName = "DEV.APP.SVRCONN";
            var queueName = "DEV.QUEUE.1";
            try
            {
                using (var transactionScope = new TransactionScope())
                {
                    Console.Write("Connecting to queue manager.. ");
                    var queueManager = new MQQueueManager(queueManagerName, channelName, connectionName);
                    Console.WriteLine("done");
                    Console.Write("Accessing queue " + queueName + ".. ");
                    var queue = queueManager.AccessQueue(queueName, MQC.MQOO_OUTPUT + MQC.MQOO_FAIL_IF_QUIESCING);
                    Console.WriteLine("done");

                    //create putMessageOptions object
                    var putMessageOptions = new MQPutMessageOptions
                    {
                        Options = MQC.MQPMO_SYNCPOINT
                    };

                    // creating a message
                    var message = new MQMessage();
                    message.WriteString("TestMessage");

                    Console.Write("Message .. ");
                    queue.Put(message, putMessageOptions);
                    Console.WriteLine("put");

                    Console.Write("Transaction ending.. ");
                    // commits the transaction
                    transactionScope.Complete();
                    Console.WriteLine("committed");

                    Console.Write("Closing queue " + queueName + ".. ");
                    queue.Close();
                    Console.WriteLine("done");

                    Console.Write("Disconnecting queue manager.. ");
                    queueManager.Disconnect();
                    Console.WriteLine("done");
                }
            }
            catch (MQException mqe)
            {
                Console.WriteLine("");
                Console.WriteLine("MQException caught: {0} - {1}", mqe.ReasonCode, mqe.Message);
                Console.WriteLine(mqe.StackTrace);
            }
        }
    }
}
0

There are 0 best solutions below