2

我对 MQMessage 代理相当陌生。在我的项目中,我想发送一条 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 应该正确初始化,以便我们能够发送整个消息。

4

1 回答 1

3

首先,您如何确定消息已损坏?您是否尝试接收发送的消息并与原始消息进行比较,或者您使用 MQExplorer 或其他方式查看了该消息。MQExplorer 默认显示消息的前 1000 个字节。要查看更多内容,您需要更改面板中的Max data bytes displayed设置。Window/Preferences/Messages

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

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

            queueMessage = new MQMessage();
            queueMessage.Format = MQC.MQFMT_STRING; 
            queueMessage.WriteString(strInputMsg);
            queuePutMessageOptions = new MQPutMessageOptions();
            queue.Put(queueMessage, queuePutMessageOptions);
于 2013-03-10T09:18:32.567 回答