使用 .Net 连接到 IBM WebSphere MQ 会引发错误 MQRC_NOT_AUTHORIZED
Connecting to IBM WebSphere MQ using .Net throws error MQRC_NOT_AUTHORIZED
我对 MQ 还很陌生,正在尝试在我的机器上配置它。要求是设置 MQ,以便我可以使用我的 C#.NET 代码 send/receive XML 文件作为 MQ 中的消息。我已经在我的机器上安装了 IBM WebSphere MQ 9.0 版本。到目前为止,据我所知,我至少需要设置队列管理器、队列和通道才能实现这一点。所以我尝试在我的 MQ 中设置这些。但是,当我尝试 运行 我的代码时,出现错误 "MQRC_NOT_AUTHORIZED".
任何人都可以指导我设置这些东西,以便通过 .NET 共享文件的方案能够正常工作吗?我想在这种情况下客户端和服务器都将在我的机器上本地?在创建队列、通道等时有许多参数可供选择,这让我感到困惑,我想我在我的设置中选择了不正确的定义。
这是我的 .Net 代码:
using IBM.WMQ;
using System;
using System.Collections;
namespace MQTest
{
class MQTest
{
public MQQueueManager ConnectMQ()
{
MQQueueManager queueManager;
// Setup connection information
Hashtable queueProperties = new Hashtable();
queueProperties[MQC.HOST_NAME_PROPERTY] = "localhost";
queueProperties[MQC.PORT_PROPERTY] = 1414;
queueProperties[MQC.CHANNEL_PROPERTY] = "QM._TEST.SVRCONN";
try
{
// Attempt the connection
queueManager = new MQQueueManager("QM_TEST", queueProperties);
Console.WriteLine("Connected Successfully");
}
catch (MQException mexc)
{
// TODO: Setup other exception handling
throw new Exception(mexc.Message
+ " ReasonCode: " + mexc.ReasonCode
+ mexc.StackTrace, mexc);
}
// For now, return the queueManager to use in reading/writing messages next
return queueManager;
}
}
}
下面是我的 MQ 设置的快照:
队列管理器
队列
频道
听众
AladdinMQ.LOCAL.ONE
首先,使用大小写混合的 MQ 对象不是一个好主意。你只是在自找麻烦。如果不使用引号,MQ 喜欢将 MQ 对象大写。因此,最好只使用大写的 MQ 对象名称。
如果您的 UserId 不在 mqm 组中,那么您需要授予您的 UserId 权限以 (1) 访问队列管理器和 (2) 访问队列。
即
做MQ权限的赌注是'Group'而不是'UserId'。假设该组需要访问以 "AladdinMQ." 开头的队列。以下是设置 OAM 权限的 setmqaut 命令:
setmqaut -m QM_TEST -t qmgr -g {GROUP} +connect +inq +dsp
setmqaut -m QM_TEST -n AladdinMQ.** -t queue -g {GROUP} +allmqi +dsp
其中 {GROUP} 是 UserId 所属组的名称。
我对 MQ 还很陌生,正在尝试在我的机器上配置它。要求是设置 MQ,以便我可以使用我的 C#.NET 代码 send/receive XML 文件作为 MQ 中的消息。我已经在我的机器上安装了 IBM WebSphere MQ 9.0 版本。到目前为止,据我所知,我至少需要设置队列管理器、队列和通道才能实现这一点。所以我尝试在我的 MQ 中设置这些。但是,当我尝试 运行 我的代码时,出现错误 "MQRC_NOT_AUTHORIZED".
任何人都可以指导我设置这些东西,以便通过 .NET 共享文件的方案能够正常工作吗?我想在这种情况下客户端和服务器都将在我的机器上本地?在创建队列、通道等时有许多参数可供选择,这让我感到困惑,我想我在我的设置中选择了不正确的定义。
这是我的 .Net 代码:
using IBM.WMQ;
using System;
using System.Collections;
namespace MQTest
{
class MQTest
{
public MQQueueManager ConnectMQ()
{
MQQueueManager queueManager;
// Setup connection information
Hashtable queueProperties = new Hashtable();
queueProperties[MQC.HOST_NAME_PROPERTY] = "localhost";
queueProperties[MQC.PORT_PROPERTY] = 1414;
queueProperties[MQC.CHANNEL_PROPERTY] = "QM._TEST.SVRCONN";
try
{
// Attempt the connection
queueManager = new MQQueueManager("QM_TEST", queueProperties);
Console.WriteLine("Connected Successfully");
}
catch (MQException mexc)
{
// TODO: Setup other exception handling
throw new Exception(mexc.Message
+ " ReasonCode: " + mexc.ReasonCode
+ mexc.StackTrace, mexc);
}
// For now, return the queueManager to use in reading/writing messages next
return queueManager;
}
}
}
下面是我的 MQ 设置的快照:
队列管理器
队列
频道
听众
AladdinMQ.LOCAL.ONE
首先,使用大小写混合的 MQ 对象不是一个好主意。你只是在自找麻烦。如果不使用引号,MQ 喜欢将 MQ 对象大写。因此,最好只使用大写的 MQ 对象名称。
如果您的 UserId 不在 mqm 组中,那么您需要授予您的 UserId 权限以 (1) 访问队列管理器和 (2) 访问队列。
即
做MQ权限的赌注是'Group'而不是'UserId'。假设该组需要访问以 "AladdinMQ." 开头的队列。以下是设置 OAM 权限的 setmqaut 命令:
setmqaut -m QM_TEST -t qmgr -g {GROUP} +connect +inq +dsp
setmqaut -m QM_TEST -n AladdinMQ.** -t queue -g {GROUP} +allmqi +dsp
其中 {GROUP} 是 UserId 所属组的名称。