【问题标题】:How to handle connection failure for subscription on WebSphere queue?如何处理 WebSphere 队列订阅的连接失败?
【发布时间】:2017-04-07 17:05:16
【问题描述】:

当一个.net windows服务连接到Websphere MQ队列订阅并不断读取消息时,我们如何处理网络断开或发生错误等问题,我们可以一直依赖MQQueueManager.IsConnected属性吗?这篇文章让我很困惑:IC75673: MQQueueManager.IsConnected property is "true" after the connection is broken in a .NET application.

下面是我必须从队列中读取消息的代码,我使用的是 MQ 版本 8.0

private MQQueueManager _queueManager;
private MQQueue _queue;
private MQTopic _topic;
public bool isSubscribed = false;

public void Subscribe()
{
    var queueManagerName = "myQueueManager";
    var properties = new Hashtable();
    //Set all the properties here
    _queueManager = new MQQueueManager(queueManagerName, properties);

    //Conect to Queue
    _queue = _queueManager.AccessQueue("devQueue", MQC.MQOO_INPUT_AS_Q_DEF);

    isSubscribed = true;
    while (isSubscribed)
    {
        if (cancellationToken.IsCancellationRequested)
        {
            isSubscribed = false;
            cancellationToken.ThrowIfCancellationRequested();
        }
        try
        {
            Receive(onMessageReceived);
        }
        catch (Exception ex)
        {
            Console.WriteLine("Exception: {0}", ex);
        }
    }   
}


public override void Receive<T>(Action<T> onMessageReceived)
{
    try
    {
        var dataReceived = new MQMessage();
        _queue.Get(dataReceived);

        T message;
        message = (T)(object)dataReceived;

        onMessageReceived(message);     
        _queueManager.Commit();
    }
    catch (Exception ex)
    {
        throw ex;
    }
}

【问题讨论】:

    标签: c# ibm-mq


    【解决方案1】:

    您链接到的 APAR IC75673 已在 MQ 的 7.0.1.6 版本中修复,该版本已发布 Aug 01 2011。 MQ v8.0 已发布June 13 2014。一般来说,任何在先前版本的 MQ 中修复的内容也将在新版本中修复。

    您的应用程序是否连接到运行该应用程序的同一 Windows 服务器上的队列管理器?在您的代码中,您没有指定诸如主机名、端口、通道名称等表明您正在通过网络使用 MQ 客户端连接的内容。您可能正在使用 MQSERVER 或 MQCHLLIB/MQCHLTAB 环境变量来提供连接详细信息。

    如果您的应用程序与队列管理器建立本地连接,则它使用所谓的“绑定模式”并且不依赖于网络。 IsConnected 方法可以很好地表明您仍然处于连接状态。文档指出,如果您的连接处于空闲状态,则提供的状态是执行最后一个活动(Get、Put 等)时的最后一个已知状态。

    如果您的应用程序通过网络建立 MQ 客户端连接,则客户端注意到连接断开的时间取决于队列管理器和 MQ 客户端之间协商的 HBINT。对于 .NET,您似乎需要使用 MQ 通道表来设置此值。 @Morag Hughson 对 StackOverflow 问题“WebSphere MQ - Changing channel definition structure using XMS.NET API”的回答提供了更多细节。您还可以查看我对 StackOverflow 问题“Setting timeout for IBM MQ”的回答,详细了解 HBINT 如何影响客户端通道的 TIMEOUT。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-10-19
      • 2015-03-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-11
      • 2021-03-08
      相关资源
      最近更新 更多