我们正在使用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,但无济于事......
修改
这就是我所看到的:
This is my trace log(很抱歉,无法在此处添加,因为我的消息将是&gt; 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的空体上崩溃了。我需要确认一些事情,以确保它不是由我项目中的其他内容引起干扰但我确信这是原因。
答案 0 :(得分:0)
异常似乎是因为收到的消息没有消息正文。如果收到的消息是由于MQRO_COD或MQRC_COA选项(在发送原始消息时设置)将没有任何消息体。当XMS尝试处理没有任何正文的消息时,它就会遇到麻烦。
在使用MQ v6时,我对这是如何工作感到困惑。您可能想要检查发送原始邮件的应用程序是否已被更改。
此外,对于XMS处理任何消息,传入消息必须包含必需的JMS头。 MQRO_COD / MQRO_COA由队列管理器自动生成,不包含JMS头。
上面的代码段中没有其他建议:
1)实际上并不需要IPEndpoint
的实例。您只需将主机名或IP地址设置为字符串,并将端口号设置为整数。
2)连接WMQ时无需设置XMSC.RTT_BROKER_PING_INTERVAL
。
3)由于您在创建会话时使用了AcknowledgeMode.AutoAcknowledge
,因此无需在message.Acknowledge()
方法中调用OnMessageReceived
。
答案 1 :(得分:0)
据我所知,这个例外确实发生在“空”的CoA的CoD上。使用MQRO_COA_WITH_DATA
/ MQRO_COD_WITH_DATA
(或甚至更大的MQRO_COA_WITH_FULL_DATA
/ MQRO_COD_WITH_FULL_DATA
)发送消息时,不会发生异常。我们将向IBM提交“PMR”以确认。