Theme
One of the common mistakes that people make when they first start programming with the MQI can be seen in this pseudo-code example:
MQMD md = {MQMD_DEFAULT}
MQGMO gmo = {MQGMO_DEFAULT}
int bufsize = 128
PMQCHAR buf = malloc(bufsize)
do {
MQGET(&md,&gmo,buf,bufsize))
} while (rc != MQRC_NO_MSG_AVAILABLE)
They complain that despite pre-loading the queue, only a single message is returned. Anyone reading this is likely to recognise immediately the problem: the MsgId of the first message is returned in the md
variable. The next iteration of the loop tries to match that MsgID and doesn’t find any more messages.
There are aspects of the MQI that try to minimise your chances of getting this wrong, like the MatchOptions
flag in the MQGMO structure. But that in turn requires you know a) to set it and b) override the default version of the structure.
Having worked with MQ for so many years, I am hopefully not going to make that kind of mistake. But I still got caught out recently by a very similar problem.
Continue reading “Variation on a theme: an MQI mistake”This post was last updated on September 20th, 2021 at 08:17 am