This is a continuation of IBM MQ Put inside .NET TransactionScope throws MQRC_NOT_AUTHORIZED, but I lack the necessary reputation to comment on that question. I've got past the error in the aforementioned post (MQRC_NOT_AUTHORIZED) and am now getting the following instead:
Connecting to queue manager.. done
Accessing queue DEV.QUEUE.1.. done
Message ..
MQException caught: 2354 - MQRC_UOW_ENLISTMENT_ERROR
at IBM.WMQ.MQDestination.Put(MQMessage message, MQPutMessageOptions pmo)
at MQTest.WMQTests.Main(String[] args) in /Users/nlc/Projects/MQTest/MQTest/Program.cs:line 38
Here is a link to a description of the error by IBM https://www.ibm.com/support/knowledgecenter/SSFKSJ_9.1.0/com.ibm.mq.tro.doc/q043830_.htm.
My example is adapted from the aforementioned post and is 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 --detach ibmcom/mq:lates
So far I've tried on macOS (.NET Core), using the IBM MQ .NET Standard client NuGet package: https://www.nuget.org/packages/IBMMQDotnetClient/
Note that if I drop the putMessageOptions in my Put() call on line 38 or drop the transaction scope, it succeeds.
This is the code:
using System;
using System.Transactions;
using IBM.WMQ;
namespace MQTest
{
public class WMQTests
{
static void Main(string[] args)
{
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);
}
}
}
}