3

我们使用 XMS.Net 连接到 WebSphere MQ 服务器 V7;这在 V6 服务器上一直运行良好,但自从“对方”升级到 V7 后,我们遇到了一些麻烦。大部分已经修复,但现在我偶然发现了一个我无法解释的错误,也找不到任何关于:

CWSMQ0282E: A null value has been used for argument BUFFER = <> NULL within method ImportMQMDMesageBuffer(WmqSession, WmqDestination, MQMD,byte[],int,int).
The preceding method detected an invalid  null argument.
If necessary, recode the application to avoid the error condition.
Stacktrace:    at IBM.XMS.Client.WMQ.WmqReceiveMarshal.ImportMQMDMesageBuffer(MQMessageDescriptor mqmd, Byte[] buffer, Int32 dataStart, Int32 dataEnd)
   at IBM.XMS.Client.WMQ.WmqAsyncConsumerShadow.Consumer(Phconn hconn, MQMessageDescriptor mqmd, MQGetMessageOptions mqgmo, Byte[] pBuffer, MQCBC mqcbc)
   at IBM.WMQ.Nmqi.UnmanagedNmqiMQ.NmqiConsumerMethodUM(Int32 hconn, IntPtr structMqmd, IntPtr structMqgmo, IntPtr buffer, IntPtr structMqcbc)

关于这个错误的原因,我认为我知道的唯一一件事是我们发送了一条消息,我期待 CoA 和 CoD 消息;我期待这些在队列中,当我关闭我的消费者监听这些消息时,其余的工作正常。

我完全不知道发生了什么……

编辑

这是最小的测试用例:

using System;
using System.Configuration;
using System.Text;
using IBM.XMS;

namespace TestApp
{
    class Program
    {
        static void Main(string[] args)
        {
            //Setup unhandled exception "logging"
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

            //Change this to your own needs!
            string QueueManager = "CONTOSO";
            string Channel = "MYCOMPANY.CONTOSO.TCP";
            string Queue = "MYCOMPANY.REPORTQ";
            string HostIP = "192.168.1.29"
            int Port = 1416;

            //Create connection
            var factoryfactory = XMSFactoryFactory.GetInstance(XMSC.CT_WMQ);
            var connectionfactory = factoryfactory.CreateConnectionFactory();

            connectionfactory.SetStringProperty(XMSC.WMQ_QUEUE_MANAGER, QueueManager);
            connectionfactory.SetStringProperty(XMSC.WMQ_HOST_NAME, HostIP);
            connectionfactory.SetIntProperty(XMSC.WMQ_PORT, Port);
            connectionfactory.SetStringProperty(XMSC.WMQ_CHANNEL, Channel);
            connectionfactory.SetIntProperty(XMSC.WMQ_BROKER_VERSION, XMSC.WMQ_BROKER_V2);
            connectionfactory.SetIntProperty(XMSC.WMQ_CONNECTION_MODE, XMSC.WMQ_CM_CLIENT_UNMANAGED);

            var connection = connectionfactory.CreateConnection();
            connection.ExceptionListener = new ExceptionListener(OnXMSExceptionReceived);

            //Create session
            var session = connection.CreateSession(false, AcknowledgeMode.ClientAcknowledge);

            //Create consumer
            var queue = session.CreateQueue(string.Format("queue://{0}/{1}", QueueManager, Queue));
            queue.SetIntProperty(XMSC.WMQ_TARGET_CLIENT, XMSC.WMQ_TARGET_DEST_MQ);  //Prevent automatic RFH (or JMS) headers in messages...
            var consumer = session.CreateConsumer(queue);
            consumer.MessageListener = new MessageListener(OnMessageReceived);  //Messages received will be handled by OnMessageReceived

            //Start the connection (which starts the consumer to listen etc.)
            Console.WriteLine("Starting");
            connection.Start();
            Console.WriteLine("Started; press any key to stop");

            //Now we wait...
            Console.ReadKey();

            //Tear down the connection
            Console.WriteLine("Stopping");
            connection.Stop();
            Console.WriteLine("Stopped; press any key to end application");

            //Keep the console around
            Console.ReadKey();
        }

        private static void OnMessageReceived(IMessage message)
        {
            Console.WriteLine("Message received");
            if (message is IBytesMessage)
            {
                var bytesmsg = (IBytesMessage)message;
                var data = new byte[bytesmsg.BodyLength];
                Console.WriteLine(Encoding.UTF8.GetString(data));
            }
            else
            {
                //The message is not an IBytesMessage, check to see if it is a Feedback-type message
                if (message.PropertyExists(XMSC.JMS_IBM_FEEDBACK))
                {
                    //Figure out which type of feedback message this is
                    int feedback = message.GetIntProperty(XMSC.JMS_IBM_FEEDBACK);
                    switch (feedback)
                    {
                        case MQC.MQFB_COA:
                            Console.WriteLine("COA received");
                            break;
                        case MQC.MQFB_COD:
                            Console.WriteLine("COD received");
                            break;
                        default:
                            //Unknown feedback type
                            Console.WriteLine("Unknown feedback");
                            break;
                    }
                }
                else
                {
                    //The message is not a feedback message; we don't know what this is so it's unexpected.
                    Console.WriteLine("Unexpected message received");
                }
            }

            Console.WriteLine("Acknowledging");
            message.Acknowledge();
            Console.WriteLine("Acknowledged");
        }

        private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            //Uh oh
            Console.WriteLine("*** UnhandledException ***");
            Console.WriteLine((e.ExceptionObject as Exception).Message);
            Console.WriteLine("******************************");
        }

        private static void OnXMSExceptionReceived(Exception ex)
        {
            //Uh oh
            Console.WriteLine("*** OnXMSExceptionReceived ***");
            Console.WriteLine(ex.Message);
            Console.WriteLine("******************************");
        }
    }
}

创建一个新的(控制台)项目,添加对 IBM.XMS.dll 的引用(C:\Program Files (x86)\IBM\WebSphere MQ\Tools\Lib\IBM.XMS.dll)并运行该项目。将任何消息放入报告队列中,看看会发生什么。

当连接到 V6 服务器时一切正常,V7 导致异常被抛出。

我们也尝试更新到 2.1.0.1 但无济于事......

编辑

这是我所看到的: 添加了更多的写入行,但崩溃很明显

这是我的跟踪日志(抱歉,无法在此处添加它,因为我的消息将超过 30000 个字符长),是一个更详细的日志(traceSpecification “all”而不是“debug”)。

我还尝试将(测试)应用程序切换到 .Net V2.0.50727.5456,但这也无济于事。

编辑

我似乎已将其范围缩小到“空”的 CoA 和 CoD;当使用 MQRO_COA_WITH_DATA 或 MQRO_COA_WITH_FULL_DATA(与 CoD 相同)而不是 MQRO_COA 发送消息时,不会发生 CWSMQ0282E 错误。所以 XMS.Net 似乎在 CoA 和 CoD 的空体上崩溃了。我需要确认一些事情以确保它不是由我的项目中的其他东西干扰引起的,但我很确定这是原因。

4

2 回答 2

0

据我所知,这个例外确实发生在“空”CoA 的 en CoD 上。MQRO_COA_WITH_DATA当使用/ MQRO_COD_WITH_DATA(甚至更大的MQRO_COA_WITH_FULL_DATA/ )发送消息时,MQRO_COD_WITH_FULL_DATA不会发生异常。我们将向 IBM 提交“PMR”以确认。

于 2012-06-28T10:57:26.050 回答
0

异常似乎是因为收到的消息没有消息正文。如果收到的消息是由于 MQRO_COD 或 MQRC_COA 选项(在发送原始消息时设置)将没有任何消息正文。当 XMS 试图处理没有任何正文的消息时,它就会遇到麻烦。

我对使用 MQ v6 时这是如何工作的感到困惑。您可能需要检查发送原始消息的应用程序是否已延迟更改。

此外,对于 XMS 处理任何消息,传入消息必须包含所需的 JMS 标头。MQRO_COD/MQRO_COA 由队列管理器自动生成,不包含 JMS 标头。

关于上面代码片段的其他一些建议:

1) 的实例IPEndpoint并不是真正需要的。您可以简单地将主机名或 IP 地址设置为字符串,将端口号设置为整数。

2)XMSC.RTT_BROKER_PING_INTERVAL连接WMQ时无需设置。

3)由于您在创建会话时使用过AcknowledgeMode.AutoAcknowledge,因此无需调用方法。message.Acknowledge()OnMessageReceived

于 2012-06-15T06:12:06.423 回答