Topic
  • 1 reply
  • Latest Post - ‏2013-04-06T11:43:14Z by aschneid
SystemAdmin
SystemAdmin
8523 Posts

Pinned topic Exception with blank message.

‏2013-04-05T19:21:49Z |
Issue while having an empty message in between actual messages

Test1 - Message1
- Message2
Test3 - Message3

When above messages are processed, there is an exception thrown.
while(if any message is available)
{
//go a read/get
mqMsg = new MQMessage();
mqGetMsgOpts = new MQGetMessageOptions();
mqQueue.Get(mqMsg);

messageData = mqMsg.ReadString(mqMsg.MessageLength); => this line fails when an empty message is processed. (exception is shown below)

}
another method(send) - sends it.

mqPutMsgOpts = new MQPutMessageOptions();
mqQueue.Put(mqMsg, mqPutMsgOpts);

How do i handle this? (so that MQ processes empty message(no data/body) without any exception and continues to the next message? Thanks in advance.
System.IO.EndOfStreamException: Unable to read beyond the end of the stream.
at System.IO.BinaryReader.ReadByte()
at System.IO.BinaryReader.Read7BitEncodedInt()
at System.IO.BinaryReader.ReadString()
at IBM.WMQ.MQMessage.ReadString(Int32 length)
I tried to add this line
messageData = mqMsg.ReadString(mqMsg.MessageLength);
mqMsg.Seek(0); => but this didn't help.
Updated on 2013-04-06T11:43:14Z at 2013-04-06T11:43:14Z by aschneid
  • aschneid
    aschneid
    5 Posts

    Re: Exception with blank message.

    ‏2013-04-06T11:43:14Z  
    Why don't you just check mqMsg.MessageLength and only call the read method when there is data (length > 0 )
    Or what is the problem then?

    Regards,
    Achim