问题描述
知道为什么下面的最小示例会通过以下命令行输出抛出 MQRC_NOT_AUTHORIZED MQException 吗?
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
该示例改编自 IBM MQ .NET 示例 SimpleXAPut.cs
(参见 https://www.ibm.com/support/knowledgecenter/SSFKSJ_7.5.0/com.ibm.mq.dev.doc/q029320_.html),并与作为 localhost 上的容器运行的 IBM MQ 一起运行:
docker run --env LICENSE=accept --env MQ_QMGR_NAME=QM1 --publish 1414:1414 --publish 9443:9443 ibmcom/mq
这在 macOS (.NET Core) 和 Windows(.NET Core 和 .NET Framework)上都会发生 - 使用 IBM MQ .NET Standard 客户端 NuGet 包:https://www.nuget.org/packages/IBMMQDotnetClient/
事务范围对于跨多个系统(即数据库和消息队列)协调事务是必要的。
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);
}
}
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)