MQ 连接 - 2009 错误

发布于 2024-09-03 22:20:00 字数 366 浏览 4 评论 0原文

我用下面的代码连接 MQ。我能够成功连接到 MQ。我的情况是我每 1 分钟将消息发送到 MQ 一次。断开电缆后,我收到 ResonCode 错误,但 IsConnected 属性仍然显示 true。这是检查连接是否仍然连接的正确方法吗?或者有什么最佳实践吗?

我想在应用程序启动时打开连接,使其永远保持打开状态。

公共静态 MQQueueManager ConnectMQ() {

if ((queueManager == null) || (!queueManager.IsConnected)||(queueManager.ReasonCode == 2009)) { 队列管理器 = 新的 MQQueueManager(); } 返回队列管理器; }

am connectting the MQ with below code. I am able connected to MQ successfully. My case is i place the messages to MQ every 1 min once. After disconnecting the cable i get a ResonCode error but IsConnected property still show true. Is this is the right way to check if the connection is still connected ? Or there any best pratcices around that.

I would like to open the connection when applicaiton is started keep it open for ever.

public static MQQueueManager ConnectMQ()
{

if ((queueManager == null) || (!queueManager.IsConnected)||(queueManager.ReasonCode == 2009))
{
queueManager = new MQQueueManager();
}
return queueManager;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

三月梨花 2024-09-10 22:20:00

WMQ 客户端连接的行为是,当空闲时,它会显示为已连接,直到 API 调用失败或连接超时。因此 isConnected() 可能会报告 true,直到尝试 get、put 或查询调用并失败,此时 QMgr 将报告已断开连接。

这里要考虑的另一件事是,2009 年并不是您可能获得的唯一代码。它恰好是连接被切断时出现的情况,但存在 QMgr 关闭、通道关闭以及各种资源和其他错误的连接代码。

通常,为了保持持续连接的要求,您需要将连接和消息处理循环包装在嵌套在 while 语句内的 try/catch 块内。当您捕获除有意退出之外的异常时,关闭对象和 QMgr,休眠至少 5 秒,然后循环到 while 的顶部。睡眠至关重要,因为如果您陷入紧密的重新连接循环并向 QMgr 进行数百次连接尝试,甚至可能使大型机 QMgr 瘫痪。

另一种方法是使用 v7 WMQ 客户端和 QMgr。通过这种组合,自动重新连接可配置为通道配置。

The behavior of the WMQ client connection is that when idle it will appear to be connected until an API call fails or the connection times out. So isConnected() will likely report true until a get, put or inquire call is attempted and fails, at which point QMgr will then report disconnected.

The other thing to consider here is that 2009 is not the only code you might get. It happens to be the one you get when the connection is severed but there are connection codes for QMgr shutting down, channel shutting down, and a variety of resource and other errors.

Typically for a requirement to maintain a constant connection you would want to wrap the connect and message processing loop inside a try/catch block nested inside a while statement. When you catch an exception other than an intentional exit, close the objects and QMgr, sleep at least 5 seconds, then loop around to the top of the while. The sleep is crucial because if you get caught in a tight reconnect loop and throw hundreds of connection attempts at the QMgr, you can bring even a mainframe QMgr to its knees.

An alternative is to use a v7 WMQ client and QMgr. With this combination, automatic reconnection is configurable as a channel configuration.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文