Hello MQ Community users,I have the following question communicated to me from an app developer at customer site:"I had the following rare case in message retrieval from a Windows MQ Queue in my C# program. My program asks a queue every second about its current depth. If the depth is bigger than 0 then the program retrieves the messages, the amount of which is the queue depth. The case is that although the queue depth was 1, getting the message caused an exception with code 2033 (no message in queue). Why did this happen? How happened that there was not a message to retrieve when the depth was 1? "Any advise on the above question will be much appreciated.Thanks in advance,Rgds, Nick.
I agree with the answer Enio has posted - likely an uncommitted message.
I would also like to offer that this is not an appropriate way for an application to operate. An application should not query the current depth of a queue to decide whether or not to attempt to get a message from the queue. The MQGET call already has a way to tell you that there is no message should you issue an MQGET call when the current depth is zero. The way it does this is to return MQRC_NO_MSG_AVAILABLE (2033). It is expected that the application should catch that return code and behave appropriately.
There are many reasons why an application should not be query the current depth before deciding to attempt to get a message:
Your question indicates that you are not handling the reason code MQRC_NO_MSG_AVAILABLE. You should fix that. Once that is done, you should remove the code that inquires the current depth and instead put whatever processing was done if the current depth was zero into the catch for reason code MQRC_NO_MSG_AVAILABLE.