简体   繁体   中英

Messages getting overwritten on IBM MQ

I am sending 3 messages

Message1 - correlation id:5000

empty message (no body/message)-correlation id:5001

Message2 - correlation id:5002

My outbound queue processes like this

Message1 - correlation id:5000

Message1-correlation id:5001 => same previous message ovewritten on the empty message. *

Message2 - correlation id:5002

The second line above should not have had Message1, instead just empty. Any thoughts?

My get method

                mqGetMsgOpts = new MQGetMessageOptions();
                if (mqQueue != null)
                {
                    //Get options for the messsage                
                    mqGetMsgOpts.Options = MQC.MQGMO_BROWSE_FIRST | MQC.MQGMO_WAIT |  MQC.MQOO_INQUIRE;
                    mqGetMsgOpts.MatchOptions = MQC.MQMO_NONE;
                    mqGetMsgOpts.WaitInterval = 5000;  // 5 seconds limit for waiting
                }

              if (mqMsg.MessageLength > 0 && mqMsg.DataLength > 0)
              {
                messageData = mqMsg.ReadString(mqMsg.MessageLength);
              }

If I don't do the length check, i will get stream reader related exception.

My put method

if(mqQueue==null)
  mqQueue = mqQMgr.AccessQueue("Queue Name", MQC.MQOO_OUTPUT | MQC.MQOO_INPUT_SHARED | MQC.MQOO_INQUIRE);

   mqMsg.WriteString(message);

I have not heard messages getting overwritten in WMQ. I suspect this must be an issue with application. This line of code:

mqGetMsgOpts.Options = MQC.MQGMO_BROWSE_FIRST | MQC.MQGMO_WAIT |  MQC.MQOO_INQUIRE;

The MQC.MQGMO_BROWSE_FIRST option will make WMQ to return always the first message that satisfies the conditions specified in MQMD structure. I can't make out from your code snippet if this option is modified at a later point to specify MQGMO_BROWSE_NEXT to read the next message in the queue.

Instead of MQC.MQGMO_BROWSE_FIRST you can specify MQGMO_BROWSE_NEXT option to continuously read messages.

Also you have specified MQC.MQOO_INQUIRE which is not valid for GMO options. You need to remove that.

More details browse options are here

I can imagine two possible issues that could cause this.

  1. Your putting application did not send an empty message body for message two.
  2. Your getting application is showing you the message buffer from message one. If there is no message buffer delivered from MQ, your previous message buffer contents will remain.

To determine which has happened to you I suggest you put all the messages, but before running your sample to get them, instead run something like the supplied sample amqsget to rule out the possibility of 1.

Then you can focus on the get buffer in your application. Make sure you are not using it if MQ said the length of the returned message is zero.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM