c# - XMS.Net 2.1.0.0/1 CWSMQ0282E

标签 c# .net ibm-mq

我们正在使用 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 但无济于事...

编辑

这是我看到的: Added a few more writelines but the crash is obvious

This is my trace log(抱歉,无法在此处添加它,因为我的消息将超过 30000 个字符)并且 here 是一个更详细的日志(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 的空体上崩溃。我需要确认一些事情以确保它不是由我的项目中的其他干扰引起的,但我很确定这就是原因。

最佳答案

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

我对使用 MQ v6 时它的工作原理感到困惑。您可能需要检查发送原始消息的应用程序是否已被延迟关闭。

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

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

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

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

3) 由于您在创建 session 时使用了AcknowledgeMode.AutoAcknowledge,因此无需在OnMessageReceived方法中调用message.Acknowledge() .

关于c# - XMS.Net 2.1.0.0/1 CWSMQ0282E,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11012046/

相关文章:

java - 在 JMS 中使用 CCDT 文件连接到 IBM MQ

c# - NetCore 6.0 如何访问dbContext文件中的连接字符串

c# - 关于 Java "Properties"和 C#' Properties 之间的区别

c# - DocumentDB LinQ 请求率大

c# - 如何在字典的第一个索引中插入元素?

c# - 按特定字符串对对象集合进行排序 C# LINQ

java - JMS Websphere MQ BytesMessge 和 TextMessage

javascript - 如何使用 Razor 语法将数组从 ViewBag 转换为 JScript 数组?

c# - 无法将字符串隐式转换为文本框

java - Tomcat 7 + JNDI 资源 + IBM WebSphere MQ