Ibm mq MQMessage deos不发送整个消息

Ibm mq MQMessage deos不发送整个消息,ibm-mq,mq,Ibm Mq,Mq,我是MQMessageBroker的新手。在我的项目中,我想发送一条xml消息。一切正常,但当消息超过500字节时,我的代码会将损坏的消息发送到队列。我正在做的是 //queueManager has been initialized in the class constructor and connected to a channel. public MQResponse WriteMsg(string QueueName, string strInputMsg)

我是MQMessageBroker的新手。在我的项目中,我想发送一条xml消息。一切正常,但当消息超过500字节时,我的代码会将损坏的消息发送到队列。我正在做的是

//queueManager has been initialized in the class constructor and connected to a channel.
        public MQResponse WriteMsg(string QueueName, string strInputMsg)
        {
            MQResponse response = new MQResponse();
            try
            {
                queue = queueManager.AccessQueue(QueueName,
                    MQC.MQOO_OUTPUT + MQC.MQOO_FAIL_IF_QUIESCING );

                queueMessage = new MQMessage();
                queueMessage.DataOffset = 0;
                //queueMessage.MessageLength = 2000000;
                queueMessage.ResizeBuffer(6 * strInputMsg.Length);
                queueMessage.WriteString(strInputMsg);
                queueMessage.Format = MQC.MQFMT_STRING;

                queuePutMessageOptions = new MQPutMessageOptions();
                queue.Put(queueMessage, queuePutMessageOptions);
                response.Message = "Message sent to the queue successfully";
                response.Status=MQResponseStatus.WriteSuccessful;
            }
            catch (MQException MQexp)
            {
                response.Message = "Exception: " + MQexp.Message;
                response.Status=MQResponseStatus.WriteFail;
                response.CatchedException=MQexp;
            }
            catch (Exception exp)
            {
                response.Message = "Exception: " + exp.Message;
                response.Status=MQResponseStatus.WriteFail;
                response.CatchedException=exp;
            }
            return response;
        }

我想queueMessage应该正确初始化,以便我们能够发送整个消息。

首先,您是如何确定消息已损坏的?您是否尝试接收发送的消息并与原始消息进行比较,或者使用MQExplorer或其他方式查看消息。默认情况下,MQExplorer显示消息的前1000个字节。要查看更多信息,您需要更改
窗口/首选项/消息
面板中显示的
最大数据字节数
设置

WebSphere MQ可以处理大小高达100 MB的消息

关于上面的代码片段:几行代码就足以构建和发送消息

            queueMessage = new MQMessage();
            queueMessage.Format = MQC.MQFMT_STRING; 
            queueMessage.WriteString(strInputMsg);
            queuePutMessageOptions = new MQPutMessageOptions();
            queue.Put(queueMessage, queuePutMessageOptions);

我使用MQ资源管理器查看队列,发现我的消息已被破坏。每次我发一条大消息,队列中就有一条坏消息。我知道每条消息最多可以有100 MB,但我不知道。正如我所说的,MQExplorer将只显示前1000个字节。您是否更改了消息首选项并尝试了?我想在Shashi的回复中添加两件事。1) 如果得到JMS异常,请打印链接的异常。JMS异常是一种多级数据结构,其中链接的异常具有特定于供应商的错误。如果应用程序没有打印它,那么调试可能会非常困难。2) 您提到使用客户端通道,但我没有看到调用任何
COMMIT
。通过网络使用异步消息传递时,始终使用事务会话和
COMMIT
方法。有关原因的解释,请参见JMS 1.1规范4.4.13消息的重复生成或我的其他SO答案。