jollyroger23
jollyroger23

Reputation: 765

Websphere MQ & .NET - WriteString() property makes message too long

So I am trying to send a message to a queue that accepts a string of max 482. The string I am sending it has a length of 452. Here is the block of code where the request queue is accessed:

            var openOptions = MQC.MQOO_OUTPUT + MQC.MQOO_FAIL_IF_QUIESCING;
            requestQueue = queueManager.AccessQueue(requestQueueName, openOptions);
            var messageObject = new MQMessage();
            messageObject.WriteString(message);
            openReplyQueue(replyQueueName);
            messageObject.ReplyToQueueName = replyQueue.Name;
            messageObject.Format = MQC.MQFMT_STRING
            messageObject.MessageType = MQC.MQMT_REQUEST;
            messageObject.Report = MQC.MQRO_COPY_MSG_ID_TO_CORREL_ID;
            messageObject.Expiry = 300;
            var pmo = new MQPutMessageOptions();
            pmo.Options = MQC.MQPMO_FAIL_IF_QUIESCING;
            requestQueue.Put(messageObject, pmo);

The code fails on the last line with the MQException Reason Code 2030. With some console output, I found out that the message length in the MQMessage object is 904, exactly double the length of the string I am trying to send and way longer than the queue's max message length.

How do I keep this buffer from happening and make sure the message length stays at 452?

Upvotes: 2

Views: 838

Answers (1)

JoshMc
JoshMc

Reputation: 10652

IBM MQ classes for .NET default to using CCSID 1200 (UTF-16) which is a Double Byte Character Set (DBCS). Because each character is represented as two bytes your 452 character string is represented as 904 bytes.

If the application getting the message from the queue is expecting 452 characters and is using the Get with Convert option, the message will be read correctly by the application. If the reading application is using an ASCII character set then this would be converted and read by the application as 452 bytes. This would also work if the getting application is reading in CCSID 1200 or another DBCS since the application is expecting 452 characters, even in a DBCS it is still getting 452 characters. If this is how your getting application works then one option is to increase the MAXMSGL of the queue to accommodate messages encoded in a DBCS.

Another option is to tell your putting application to put the message in a ASCII character set such as CCSID 437.

To set the CCSID to 437 use the following:

messageObject.CharacterSet = 437;

Upvotes: 2

Related Questions