gpt4 book ai didi

c++ - 在 C# 中连接到 Websphere MQ 有效,但在 C++ 中失败,代码为 2058 (MQRC_Q_MGR_NAME_ERROR)

转载 作者:行者123 更新时间:2023-11-30 05:10:53 27 4
gpt4 key购买 nike

我需要编写一段代码,使用 C++ 将消息放入 MQ。当我在本地主机上测试它时,使用默认端口 (1414) 它可以工作。但是,在使用特定 channel 定义和不同端口 (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

有什么想法吗?

最佳答案

ImqChannel * pChannel_ = 0;  // Channel definition which is at class level
ImqQueueManager queueManager_; // Queue Manager, also declared at class level

变量名中多出的下划线是怎么回事?

queueManager_.setName("QM");

那是远程队列管理器的实际队列管理器名称吗?它必须是正确的值。注意:MQ 区分大小写。 IE。 “QM”与“qm”不同。

每个队列管理器的监听器监听不同的端口。

pChannel_->setConnectionName("10.2.3.4(1420)");

您确定队列管理器“QM”实际上正在监听端口 1420 而不是 1414、1419 或 1421 等。

关于c++ - 在 C# 中连接到 Websphere MQ 有效,但在 C++ 中失败,代码为 2058 (MQRC_Q_MGR_NAME_ERROR),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45420877/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com