Search code examples
ibm-mqmq

MQMessage deos not send whole message


I am fairly new to MQMessage broker. In my project, I want to send an xml message. Every thing is ok but when message get larger than 500 bytes, My code send broken message to the Queue. what I am doing is

//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;
        }

I guess queueMessage should be initialized correctly so that we able to send whole message.


Solution

  • First of all how did you determine that the message is broken? Did you try to receive the sent message and compared with the original message or you viewed the message using MQExplorer or some other means. MQExplorer by default displays first 1000 bytes of the message. To view more you need to change the Max data bytes displayed setting in Window/Preferences/Messages panel.

    WebSphere MQ can handle messages of size as large as 100 MB.

    Regarding your code snippet above: The few lines of code is enough to build and send a message.

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