{"id":994,"date":"2021-09-20T08:15:47","date_gmt":"2021-09-20T07:15:47","guid":{"rendered":"https:\/\/marketaylor.synology.me\/?p=994"},"modified":"2021-09-20T08:17:08","modified_gmt":"2021-09-20T07:17:08","slug":"variation-on-a-theme-an-mqi-mistake","status":"publish","type":"post","link":"https:\/\/marketaylor.synology.me\/?p=994","title":{"rendered":"Variation on a theme: an MQI mistake"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">Theme<\/h3>\n\n\n\n<p>One of the common mistakes that people make when they first start programming with the MQI can be seen in this pseudo-code example:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">MQMD md = {MQMD_DEFAULT}\nMQGMO gmo = {MQGMO_DEFAULT}\nint bufsize = 128\nPMQCHAR buf = malloc(bufsize)\ndo {\n  MQGET(&amp;md,&amp;gmo,buf,bufsize))\n} while (rc != MQRC_NO_MSG_AVAILABLE)<\/pre>\n\n\n\n<p>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 <em>MsgId <\/em>of the first message is returned in the <code>md<\/code> variable. The next iteration of the loop tries to match that <em>MsgID <\/em>and doesn&#8217;t find any more messages. <\/p>\n\n\n\n<p>There are aspects of the MQI that try to minimise your chances of getting this wrong, like the <code>MatchOptions<\/code> 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.<\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<!--more-->\n\n\n\n<h3 class=\"wp-block-heading\">Variation<\/h3>\n\n\n\n<p>The pseudo-code for my program looks like this:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">MQMD md = {MQMD_DEFAULT}\nMQGMO gmo = {MQGMO_DEFAULT}\nint bufsize = 128\nPMQCHAR buf\ngmo.Options = MQGMO_CONVERT\ndo {\n  bufsize = bufsize*2\n  buf = malloc(bufsize) \/\/ Increase the buffer on each loop\n  MQGET(&amp;md,&amp;gmo, buf, bufsize)\n} while (rc == MQRC_TRUNCATED_MSG_FAILED)<\/pre>\n\n\n\n<p>This again is not the real compilable code but it should explain the principle. So you can ignore the apparent memory leak. The idea is that since we don&#8217;t know how big the message is, we keep enlarging the data buffer until we can get the full message. And my system behaved as expected when I tested it.<\/p>\n\n\n\n<p>But I got reports of corrupt message data when the program ran as a client to a z\/OS system. It was very easy to debug once I reproduced the environment. It &#8211; annoyingly and perhaps embarrassingly &#8211; turned out to be a lot like the <em>MsgId <\/em>problem. The returned <code>md<\/code> variable is modified not only with the <em>MsgId <\/em>but also with the <em>CodedCharSetId <\/em>(codepage) and <em>Encoding <\/em>(endianness) of the message even when the MQGET fails. Since I wasn&#8217;t resetting the <code>md<\/code> contents inside the loop, the second attempt asks for the data to be converted into its own codepage and endianness. So the message data is not in fact converted, and hence it looks corrupt.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Coda<\/h3>\n\n\n\n<p>This was very easy to fix once I&#8217;d diagnosed the problem. But I&#8217;ve not seen this specific issue before, so perhaps this can be a warning to others.<\/p>\n<p class=\"last-modified\" style=\"border:1px solid;padding: 10px;\">This post was last updated on September 20th, 2021 at 08:17 am<\/p>","protected":false},"excerpt":{"rendered":"<p>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(&amp;md,&amp;gmo,buf,bufsize)) } while (rc != MQRC_NO_MSG_AVAILABLE) They complain that despite pre-loading the queue, &hellip; <a href=\"https:\/\/marketaylor.synology.me\/?p=994\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Variation on a theme: an MQI mistake&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[5],"tags":[35,20],"class_list":["post-994","post","type-post","status-publish","format-standard","hentry","category-mq","tag-ibmmq","tag-mqseries"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Variation on a theme: an MQI mistake - Mark Taylor&#039;s Blog<\/title>\n<meta name=\"description\" content=\"This shows an example of a mistake that is a variation on a common programming error when using the MQ API\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/marketaylor.synology.me\/?p=994\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Variation on a theme: an MQI mistake - Mark Taylor&#039;s Blog\" \/>\n<meta property=\"og:description\" content=\"This shows an example of a mistake that is a variation on a common programming error when using the MQ API\" \/>\n<meta property=\"og:url\" content=\"https:\/\/marketaylor.synology.me\/?p=994\" \/>\n<meta property=\"og:site_name\" content=\"Mark Taylor&#039;s Blog\" \/>\n<meta property=\"article:published_time\" content=\"2021-09-20T07:15:47+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-09-20T07:17:08+00:00\" \/>\n<meta name=\"author\" content=\"Mark\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@marketaylor\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Mark\" \/>\n\t<meta name=\"twitter:label2\" content=\"Estimated reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/marketaylor.synology.me\\\/?p=994#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/marketaylor.synology.me\\\/?p=994\"},\"author\":{\"name\":\"Mark\",\"@id\":\"https:\\\/\\\/marketaylor.synology.me\\\/#\\\/schema\\\/person\\\/2d6f4113ff54187023e20c20186bbb3c\"},\"headline\":\"Variation on a theme: an MQI mistake\",\"datePublished\":\"2021-09-20T07:15:47+00:00\",\"dateModified\":\"2021-09-20T07:17:08+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/marketaylor.synology.me\\\/?p=994\"},\"wordCount\":371,\"commentCount\":0,\"keywords\":[\"ibmmq\",\"mqseries\"],\"articleSection\":[\"IBM MQ\"],\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/marketaylor.synology.me\\\/?p=994#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/marketaylor.synology.me\\\/?p=994\",\"url\":\"https:\\\/\\\/marketaylor.synology.me\\\/?p=994\",\"name\":\"Variation on a theme: an MQI mistake - Mark Taylor&#039;s Blog\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/marketaylor.synology.me\\\/#website\"},\"datePublished\":\"2021-09-20T07:15:47+00:00\",\"dateModified\":\"2021-09-20T07:17:08+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/marketaylor.synology.me\\\/#\\\/schema\\\/person\\\/2d6f4113ff54187023e20c20186bbb3c\"},\"description\":\"This shows an example of a mistake that is a variation on a common programming error when using the MQ API\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/marketaylor.synology.me\\\/?p=994#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/marketaylor.synology.me\\\/?p=994\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/marketaylor.synology.me\\\/?p=994#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/marketaylor.synology.me\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Variation on a theme: an MQI mistake\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/marketaylor.synology.me\\\/#website\",\"url\":\"https:\\\/\\\/marketaylor.synology.me\\\/\",\"name\":\"Mark Taylor&#039;s Blog\",\"description\":\"Messaging, Music and Moving Around\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/marketaylor.synology.me\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-GB\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/marketaylor.synology.me\\\/#\\\/schema\\\/person\\\/2d6f4113ff54187023e20c20186bbb3c\",\"name\":\"Mark\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/9a5ae091c43730194cba7cabb5d65c1dc3f48d05caaddec6ff2319a1ce66376f?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/9a5ae091c43730194cba7cabb5d65c1dc3f48d05caaddec6ff2319a1ce66376f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/9a5ae091c43730194cba7cabb5d65c1dc3f48d05caaddec6ff2319a1ce66376f?s=96&d=mm&r=g\",\"caption\":\"Mark\"},\"sameAs\":[\"https:\\\/\\\/x.com\\\/marketaylor\"],\"url\":\"https:\\\/\\\/marketaylor.synology.me\\\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Variation on a theme: an MQI mistake - Mark Taylor&#039;s Blog","description":"This shows an example of a mistake that is a variation on a common programming error when using the MQ API","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/marketaylor.synology.me\/?p=994","og_locale":"en_GB","og_type":"article","og_title":"Variation on a theme: an MQI mistake - Mark Taylor&#039;s Blog","og_description":"This shows an example of a mistake that is a variation on a common programming error when using the MQ API","og_url":"https:\/\/marketaylor.synology.me\/?p=994","og_site_name":"Mark Taylor&#039;s Blog","article_published_time":"2021-09-20T07:15:47+00:00","article_modified_time":"2021-09-20T07:17:08+00:00","author":"Mark","twitter_card":"summary_large_image","twitter_creator":"@marketaylor","twitter_misc":{"Written by":"Mark","Estimated reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/marketaylor.synology.me\/?p=994#article","isPartOf":{"@id":"https:\/\/marketaylor.synology.me\/?p=994"},"author":{"name":"Mark","@id":"https:\/\/marketaylor.synology.me\/#\/schema\/person\/2d6f4113ff54187023e20c20186bbb3c"},"headline":"Variation on a theme: an MQI mistake","datePublished":"2021-09-20T07:15:47+00:00","dateModified":"2021-09-20T07:17:08+00:00","mainEntityOfPage":{"@id":"https:\/\/marketaylor.synology.me\/?p=994"},"wordCount":371,"commentCount":0,"keywords":["ibmmq","mqseries"],"articleSection":["IBM MQ"],"inLanguage":"en-GB","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/marketaylor.synology.me\/?p=994#respond"]}]},{"@type":"WebPage","@id":"https:\/\/marketaylor.synology.me\/?p=994","url":"https:\/\/marketaylor.synology.me\/?p=994","name":"Variation on a theme: an MQI mistake - Mark Taylor&#039;s Blog","isPartOf":{"@id":"https:\/\/marketaylor.synology.me\/#website"},"datePublished":"2021-09-20T07:15:47+00:00","dateModified":"2021-09-20T07:17:08+00:00","author":{"@id":"https:\/\/marketaylor.synology.me\/#\/schema\/person\/2d6f4113ff54187023e20c20186bbb3c"},"description":"This shows an example of a mistake that is a variation on a common programming error when using the MQ API","breadcrumb":{"@id":"https:\/\/marketaylor.synology.me\/?p=994#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/marketaylor.synology.me\/?p=994"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/marketaylor.synology.me\/?p=994#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/marketaylor.synology.me\/"},{"@type":"ListItem","position":2,"name":"Variation on a theme: an MQI mistake"}]},{"@type":"WebSite","@id":"https:\/\/marketaylor.synology.me\/#website","url":"https:\/\/marketaylor.synology.me\/","name":"Mark Taylor&#039;s Blog","description":"Messaging, Music and Moving Around","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/marketaylor.synology.me\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-GB"},{"@type":"Person","@id":"https:\/\/marketaylor.synology.me\/#\/schema\/person\/2d6f4113ff54187023e20c20186bbb3c","name":"Mark","image":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/secure.gravatar.com\/avatar\/9a5ae091c43730194cba7cabb5d65c1dc3f48d05caaddec6ff2319a1ce66376f?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/9a5ae091c43730194cba7cabb5d65c1dc3f48d05caaddec6ff2319a1ce66376f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/9a5ae091c43730194cba7cabb5d65c1dc3f48d05caaddec6ff2319a1ce66376f?s=96&d=mm&r=g","caption":"Mark"},"sameAs":["https:\/\/x.com\/marketaylor"],"url":"https:\/\/marketaylor.synology.me\/?author=1"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/marketaylor.synology.me\/index.php?rest_route=\/wp\/v2\/posts\/994","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/marketaylor.synology.me\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/marketaylor.synology.me\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/marketaylor.synology.me\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/marketaylor.synology.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=994"}],"version-history":[{"count":4,"href":"https:\/\/marketaylor.synology.me\/index.php?rest_route=\/wp\/v2\/posts\/994\/revisions"}],"predecessor-version":[{"id":998,"href":"https:\/\/marketaylor.synology.me\/index.php?rest_route=\/wp\/v2\/posts\/994\/revisions\/998"}],"wp:attachment":[{"href":"https:\/\/marketaylor.synology.me\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=994"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/marketaylor.synology.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=994"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/marketaylor.synology.me\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=994"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}