{"id":1531,"date":"2024-01-04T11:21:37","date_gmt":"2024-01-04T11:21:37","guid":{"rendered":"https:\/\/marketaylor.synology.me\/?p=1531"},"modified":"2025-07-20T07:17:56","modified_gmt":"2025-07-20T06:17:56","slug":"mqi-callback","status":"publish","type":"post","link":"https:\/\/marketaylor.synology.me\/?p=1531","title":{"rendered":"Unexpected behaviour in MQI Callback"},"content":{"rendered":"\n<p>While investigating a reported issue in the <a href=\"https:\/\/github.com\/ibm-messaging\/mq-mqi-nodejs\" target=\"_blank\" rel=\"noreferrer noopener\">MQI NodeJS bindings<\/a>, I had to dig into the C library&#8217;s MQI callback functions. I found some behaviour that I didn&#8217;t expect. And some slight differences depending on whether you run an application with local or client bindings. [This difference turned out to be a defect in the MQ client, fixed in MQ 9.4.3 &#8211; discussed further below.]<\/p>\n\n\n\n<!--more-->\n\n\n\n<h3 class=\"wp-block-heading\">MQI Callbacks<\/h3>\n\n\n\n<p>The C MQI can drive callback functions when messages arrive on queues, giving an asynchronous approach for your applications. You don&#8217;t need to sit in a blocking MQGET(WAIT) or polling loop to retrieve the messages. The MQCB verb sets up the callback; you give it a function address and the MQ libraries call that function when needed.<\/p>\n\n\n\n<p>When you register the callback function through MQCB, one of the options is to choose which type of callbacks to receive. The <code>MQCBD-&gt;CallbackType<\/code>field can be set to either <code>MQCBT_EVENT_HANDLER<\/code> or <code>MQCBT_MESSAGE_CONSUMER<\/code>. If you look at the <em>amqsghac.c<\/em> sample program, you will see how it uses Events to report on the reconnection attempts made automatically by the client library.<\/p>\n\n\n\n<p>The callback function itself has a number of parameters. For this article, the interesting parameter is the MQCBC (CallbackContext) structure. Within that structure, 3 relevant fields are the <code>Reason<\/code>, <code>CallType<\/code> and <code>Hobj<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">The unexpected behaviour<\/h3>\n\n\n\n<p>I had a program that registered a Message Consumer callback. But I was surprised to find that sometimes the <code>CallType<\/code> was set to <code>MQCBCT_EVENT<\/code>. Why was I being given an Event, when I had not registered to receive one? <\/p>\n\n\n\n<p>It turns out that this is correct, and is even <a href=\"https:\/\/www.ibm.com\/docs\/en\/ibm-mq\/latest?topic=context-calltype-mqlong-mqcbc\" target=\"_blank\" rel=\"noreferrer noopener\">documented<\/a> as such. But I wasn&#8217;t expecting it. There is a subtle distinction between the <code>CallType<\/code> and <code>CallbackType<\/code> fields in their respective MQI structures.<\/p>\n\n\n\n<p>With a synchronous MQGET, if you end the queue manager, the verb is given an Reason code like <code>MQRC_QMGR_QUIESCING<\/code>. But with the asynchronous operation, the equivalent notification is given by an Event instead of being tied to, say, a <code>MSG_NOT_REMOVED<\/code> call type. Basically, failed MQGET responses are split into two types &#8211; those that are considered events, and those not.<\/p>\n\n\n\n<p>So a Message Consumer callback function must be prepared to deal with the Event CallType. <\/p>\n\n\n\n<p>Once I&#8217;d worked out what was going on, it was fine. It just took a slight reset of how I was thinking of the processing.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Clients and Local bindings<\/h3>\n\n\n\n<p>I did find one slight difference between local bindings and client connection. The difference should not be important, and most properly-written programs ought not to care. But I thought it worth noting anyway.<\/p>\n\n\n\n<p>When the Message Consumer callback runs in local bindings mode, the associated <code>Hobj<\/code> is set to the value that was specified during the corresponding MQCB even when the callback happens for a connection-wide Event such as the queue manager being shutdown. <\/p>\n\n\n\n<p>But in client mode, the <code>Hobj<\/code> is set to 0. <\/p>\n\n\n\n<p><strong>Note: This behaviour turned out to be a bug in the client layer; it was fixed in MQ 9.4.3 so the <code>Hobj<\/code> is now the same as the local bindings mode. But you may still need to be aware of the bug if you are working with older versions of MQ.<\/strong><\/p>\n\n\n\n<p>Given that the queue manager is being shutdown, you would usually not be expected or able to make any additional &#8220;cleanup&#8221; calls such as using the <code>Hobj<\/code> to MQCLOSE the queue. So the application should always ignore the <code>Hobj<\/code>. Depending on how the queue manager is ending, you might have the opportunity to commit\/backout any in-flight transactions; those don&#8217;t depend on the object handle. But again, this <code>Hobj<\/code> difference was slightly confusing.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Conclusion<\/h3>\n\n\n\n<p>Seeing an event when I wasn&#8217;t expecting one, and seeing different object handle values than I was expecting, made me think at first that there might be a bug in one of the MQI libraries. It turns out that there isn&#8217;t. <\/p>\n\n\n\n<p>It mattered to me because of the packages I have released that wrap the C MQI functions for use in other environments. But I thought I&#8217;d write this up to help or warn anyone else who might be doing something similar.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Updates:<\/h3>\n\n\n\n<p>2025\/07\/20: Reference to bug fix in MQ client code<\/p>\n<p class=\"last-modified\" style=\"border:1px solid;padding: 10px;\">This post was last updated on July 20th, 2025 at 07:17 am<\/p>","protected":false},"excerpt":{"rendered":"<p>While investigating a reported issue in the MQI NodeJS bindings, I had to dig into the C library&#8217;s MQI callback functions. I found some behaviour that I didn&#8217;t expect. And some slight differences depending on whether you run an application with local or client bindings. [This difference turned out to be a defect in the &hellip; <a href=\"https:\/\/marketaylor.synology.me\/?p=1531\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Unexpected behaviour in MQI Callback&#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":[],"class_list":["post-1531","post","type-post","status-publish","format-standard","hentry","category-mq"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Unexpected behaviour in MQI Callback - Mark Taylor&#039;s Blog<\/title>\n<meta name=\"description\" content=\"The MQI Callback feature had behaviour that I didn&#039;t expect. I explais what I found, and the differences between local and client connections\" \/>\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=1531\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Unexpected behaviour in MQI Callback - Mark Taylor&#039;s Blog\" \/>\n<meta property=\"og:description\" content=\"The MQI Callback feature had behaviour that I didn&#039;t expect. I explais what I found, and the differences between local and client connections\" \/>\n<meta property=\"og:url\" content=\"https:\/\/marketaylor.synology.me\/?p=1531\" \/>\n<meta property=\"og:site_name\" content=\"Mark Taylor&#039;s Blog\" \/>\n<meta property=\"article:published_time\" content=\"2024-01-04T11:21:37+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-07-20T06:17:56+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=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/marketaylor.synology.me\\\/?p=1531#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/marketaylor.synology.me\\\/?p=1531\"},\"author\":{\"name\":\"Mark\",\"@id\":\"https:\\\/\\\/marketaylor.synology.me\\\/#\\\/schema\\\/person\\\/2d6f4113ff54187023e20c20186bbb3c\"},\"headline\":\"Unexpected behaviour in MQI Callback\",\"datePublished\":\"2024-01-04T11:21:37+00:00\",\"dateModified\":\"2025-07-20T06:17:56+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/marketaylor.synology.me\\\/?p=1531\"},\"wordCount\":689,\"commentCount\":3,\"articleSection\":[\"IBM MQ\"],\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/marketaylor.synology.me\\\/?p=1531#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/marketaylor.synology.me\\\/?p=1531\",\"url\":\"https:\\\/\\\/marketaylor.synology.me\\\/?p=1531\",\"name\":\"Unexpected behaviour in MQI Callback - Mark Taylor&#039;s Blog\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/marketaylor.synology.me\\\/#website\"},\"datePublished\":\"2024-01-04T11:21:37+00:00\",\"dateModified\":\"2025-07-20T06:17:56+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/marketaylor.synology.me\\\/#\\\/schema\\\/person\\\/2d6f4113ff54187023e20c20186bbb3c\"},\"description\":\"The MQI Callback feature had behaviour that I didn't expect. I explais what I found, and the differences between local and client connections\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/marketaylor.synology.me\\\/?p=1531#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/marketaylor.synology.me\\\/?p=1531\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/marketaylor.synology.me\\\/?p=1531#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/marketaylor.synology.me\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Unexpected behaviour in MQI Callback\"}]},{\"@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":"Unexpected behaviour in MQI Callback - Mark Taylor&#039;s Blog","description":"The MQI Callback feature had behaviour that I didn't expect. I explais what I found, and the differences between local and client connections","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=1531","og_locale":"en_GB","og_type":"article","og_title":"Unexpected behaviour in MQI Callback - Mark Taylor&#039;s Blog","og_description":"The MQI Callback feature had behaviour that I didn't expect. I explais what I found, and the differences between local and client connections","og_url":"https:\/\/marketaylor.synology.me\/?p=1531","og_site_name":"Mark Taylor&#039;s Blog","article_published_time":"2024-01-04T11:21:37+00:00","article_modified_time":"2025-07-20T06:17:56+00:00","author":"Mark","twitter_card":"summary_large_image","twitter_creator":"@marketaylor","twitter_misc":{"Written by":"Mark","Estimated reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/marketaylor.synology.me\/?p=1531#article","isPartOf":{"@id":"https:\/\/marketaylor.synology.me\/?p=1531"},"author":{"name":"Mark","@id":"https:\/\/marketaylor.synology.me\/#\/schema\/person\/2d6f4113ff54187023e20c20186bbb3c"},"headline":"Unexpected behaviour in MQI Callback","datePublished":"2024-01-04T11:21:37+00:00","dateModified":"2025-07-20T06:17:56+00:00","mainEntityOfPage":{"@id":"https:\/\/marketaylor.synology.me\/?p=1531"},"wordCount":689,"commentCount":3,"articleSection":["IBM MQ"],"inLanguage":"en-GB","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/marketaylor.synology.me\/?p=1531#respond"]}]},{"@type":"WebPage","@id":"https:\/\/marketaylor.synology.me\/?p=1531","url":"https:\/\/marketaylor.synology.me\/?p=1531","name":"Unexpected behaviour in MQI Callback - Mark Taylor&#039;s Blog","isPartOf":{"@id":"https:\/\/marketaylor.synology.me\/#website"},"datePublished":"2024-01-04T11:21:37+00:00","dateModified":"2025-07-20T06:17:56+00:00","author":{"@id":"https:\/\/marketaylor.synology.me\/#\/schema\/person\/2d6f4113ff54187023e20c20186bbb3c"},"description":"The MQI Callback feature had behaviour that I didn't expect. I explais what I found, and the differences between local and client connections","breadcrumb":{"@id":"https:\/\/marketaylor.synology.me\/?p=1531#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/marketaylor.synology.me\/?p=1531"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/marketaylor.synology.me\/?p=1531#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/marketaylor.synology.me\/"},{"@type":"ListItem","position":2,"name":"Unexpected behaviour in MQI Callback"}]},{"@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\/1531","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=1531"}],"version-history":[{"count":6,"href":"https:\/\/marketaylor.synology.me\/index.php?rest_route=\/wp\/v2\/posts\/1531\/revisions"}],"predecessor-version":[{"id":1775,"href":"https:\/\/marketaylor.synology.me\/index.php?rest_route=\/wp\/v2\/posts\/1531\/revisions\/1775"}],"wp:attachment":[{"href":"https:\/\/marketaylor.synology.me\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1531"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/marketaylor.synology.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1531"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/marketaylor.synology.me\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1531"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}