【发布时间】:2017-07-31 16:21:04
【问题描述】:
我需要编写一段代码来使用 C++ 将消息放入 MQ。当我在 localhost 上测试它时,使用默认端口(1414)它可以工作。但是,在使用特定通道定义和不同端口(1420)的实际环境中,它会失败,原因代码为 2058 / MQRC_Q_MGR_NAME_ERROR。 使用 Websphere MQ Explorer 连接到远程 MQ 没有问题。在 C# 应用程序中连接到同一个远程服务器以证明连接性也没有问题。有什么想法可能导致它吗?
一些示例代码摘录:调用 .connect() 时失败的 C++...
ImqChannel * pChannel_ = 0; // Channel definition which is at class level
ImqQueueManager queueManager_; // Queue Manager, also declared at class level
// extract from the MQHelper::Connect() method...
int MQClient::Connect() {
pChannel_ = new ImqChannel;
pChannel_->setChannelName("CLCHL.QM");
pChannel_->setTransportType(MQXPT_TCP);
pChannel_->setConnectionName("10.2.3.4(1420)");
// Should we set this???! pChannel_->setModeName("to what?");
queueManager_.setName("QM");
queueManager_.setChannelReference(pChannel_);
if (!queueManager_.connect()) {
// ERROR IS HERE: _lastCompletionCode is 2, _lastReasonCode is 2058
_lastCompletionCode = queueManager_.completionCode();
_lastReasonCode = queueManager_.reasonCode();
return (int)_lastReasonCode;
}
// If we get here, we're all good:
return 0;
}
在C#中,没有这样的问题:下面的代码可以正常连接..
queueManager = new MQQueueManager("QM", "CLCHL.QM", "10.2.3.4(1420)");
其他信息:
- Server MQ 安装为 7.0.1.0 Websphere MQ Explorer 版本:
- 7.5.0.1(在这里连接没问题)在 C# 应用程序中,我只引用 amqmdnet.dll ......一切都很好。
- 在 C++ 应用程序中,我为 26 个不同的 mq .h 或 .hpp 文件设置了外部依赖项。
- 我还包含了适当的库等...再次 - 我知道它是 能够像它一样工作,相同的代码将指向一个 本地主机队列管理器。
- 我正在使用 VS 2017
有什么想法吗?
【问题讨论】:
-
QM 名称不是必填字段。您可以尝试删除 QM 名称,看看它是否有效
-
嗨,我注释掉了 .setName("QM") 语句。这导致原因代码为 2059 / MQRC_Q_MGR_NAME_ERROR。所以那里没有快乐。
-
c#应用程序和c++应用程序的唯一区别可能是“setTransportType(MQXPT_TCP);”
-
"setTransportType(MQXPT_TCP);" - 这是正确的 - 有关程序的编译/链接,请参阅下面的 cmets。
标签: c++ visual-studio c++11 ibm-mq