Description
mq-mqi-nodejs version - 2.0.1
I am trying to use this package to get messages using MQGMO_SYNCPOINT
flag in the gmo
(get message options) object.
const mq = require('ibmmq')
gmo.Options =
MQC.MQGMO_SYNCPOINT |
MQC.MQGMO_WAIT |
MQC.MQGMO_CONVERT |
MQC.MQGMO_FAIL_IF_QUIESCING;
gmo.MatchOptions = MQC.MQMO_NONE;
gmo.WaitInterval = this.waitInterval * 1000; // 60 seconds during testing
mq.Get(this.queueHandle, new mq.MQMD(), gmo, this.getMessagesCB);
The MQGMO_SYNCPOINT
option ensures that the message is not removed from the queue until I later commit the message using mq.Cmit
call.
However, when I make that Cmit
call in my callback function (this.getMessagesCB
) e.g.
getMessagesCB(error, hObj, gmo, md, buf, hConn) {
mq.Cmit(this.connectionHandle, function (err) {
if (err) {
console.log("Error on commit", err);
}
});
}
I get the following error:
{
"name": "MQError",
"message": "CMIT: MQCC = MQCC_FAILED [2] MQRC = MQRC_HCONN_ASYNC_ACTIVE [2500]",
"mqcc": 2,
"mqccstr": "MQCC_FAILED",
"mqrc": 2500,
"mqrcstr": "MQRC_HCONN_ASYNC_ACTIVE",
"version": "2.0.1",
"verb": "CMIT"
}
With this new version of 'ibmmq' NodeJS package, we have to call the Ctl
method with one of the start options. I am using MQOP_START
as shown in the samples included in the v2 version. e.g.
mq.Ctl(this.connectionHandle, mq.MQC.MQOP_START, function (error) {
if (error) {
console.log(`error sending MQOP_START control call: ${error}`)
}
})
Reading the control callbacks documentation says:
MQOP_START Start the consuming of messages for all defined message consumer functions for the specified connection handle.
Callbacks run on a thread started by the system, which is different from any of the application threads.
This operation gives control of the provided connection handle to system. The only MQI calls which can be issued by a thread other than the consumer thread are:
- MQCTL with Operation MQOP_STOP
- MQCTL with Operation MQOP_SUSPEND
- MQDISC - Performs MQCTL with Operation MQOP_STOP before disconnection the HConn.
- MQRC_HCONN_ASYNC_ACTIVE is returned if an IBM® MQ API call is issued while the connection handle is started, and the call does not originate from a message consumer function.
So, I tried, issuing a new Ctl
call with MQOP_STOP
, before calling mq.Cmit
e.g.
mq.Ctl(this.connectionHandle, mq.MQC.MQOP_STOP, function (error) {
if (error) {
logError({ msg: `mq.CTL STOP error: ${formatErr(error)}`, error });
} else {
logInfo(`initiated MQOP_STOP`);
mq.Cmit(this.connectionHandle, this.callbackOnCommit);
}
});
Now I get a different error:
libc++abi: terminating due to uncaught exception of type Napi::Error
I suspect, this is because I have no way of accessing the correct thread from within NodeJS, to issue the Cmit
command.
Could you please provide a working example of using MQGMO_SYNCPOINT
to get a message non-destructively from a queue and then later commit the message using Cmit
?