简体   繁体   English

异常后的Websphere MQ isConnected变量

[英]Websphere MQ isConnected variable after exception

I use an C# Console Application to put and read messages of the MQ.. When the application starts, it connect once with the MQ and then the connection should be always upholded. 我使用C#控制台应用程序来放置和读取MQ的消息。当应用程序启动时,它与MQ连接一次,然后应始终保持该连接。 The program runs every 30 sec and check if new messages are in the queue or a database(to put them on the queue) and check the isConnected-variable if its true. 该程序每30秒运行一次,检查新消息是否在队列或数据库中(将它们放入队列中),并检查isConnected变量是否为true。

  • But what happen if an exception(2009 - connection broke) in the Put/Get occur? 但是,如果Put / Get中发生异常(2009-连接中断),会发生什么情况? Will the isConnected automatically set to false? 将isConnected自动设置为false吗?
  • Is the connection automatically disconnected or do I have to call Disconnect() in the error handling? 连接是否自动断开连接,还是必须在错误处理中调用Disconnect()?

Thanks! 谢谢!

To answer your exact question, for a basic .net application (non XMS) using MQQueue for put/get, if you get CERTAIN bad return codes from the underlying API call which indicates a connection issue, MQ will attempt an MQBACK and an MQDISC for you and will result in the connection handle being invalidated (IsConnected would return false) and an exception being thrown. 为了回答您的确切问题,对于使用MQQueue进行放置/获取的基本.net应用程序(非XMS),如果您从底层API调用中获得了指示连接问题的CERTAIN错误返回码,则MQ将尝试使用MQBACK和MQDISC您将导致连接句柄失效(IsConnected将返回false)并引发异常。 However if an exception occurs outside those return codes then no attempt is made to do anything with the connection. 但是,如果在这些返回代码之外发生异常,则不会尝试对连接执行任何操作。

Basically you should not code an application relying on this behaviour, when the most simple answer is to always disconnect if you get an exception which relates to the quality of the connection or queue manager. 基本上,您不应该编写依赖于此行为的应用程序,最简单的答案是,如果遇到与连接或队列管理器质量有关的异常,则始终断开连接。 For example, a no message available etc type exception doesnt mean you need to disconnect but a connection broken obviously does. 例如,没有可用消息等类型异常并不意味着您需要断开连接,但显然断开连接确实需要断开连接。 There is no harm in calling disconnect on an already disconnected connection. 在已经断开的连接上调用断开连接没有任何危害。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM