Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function getMessage() {
var md = new mq.MQMD();
var gmo = new mq.MQGMO();
gmo.Options = MQC.MQGMO_NO_SYNCPOINT |
MQC.MQGMO_WAIT |
MQC.MQGMO_CONVERT |
MQC.MQGMO_FAIL_IF_QUIESCING;
gmo.MatchOptions = MQC.MQMO_NONE;
gmo.WaitInterval = waitInterval * 1000; // 3 seconds
if (msgId != null) {
console.log("Setting Match Option for MsgId");
gmo.MatchOptions = MQC.MQMO_MATCH_MSG_ID;
md.MsgId = hexToBytes(msgId);
}
// Set up the callback handler to be invoked when there
gmo.MatchOptions = MQC.MQMO_NONE;
gmo.WaitInterval = waitInterval * 1000; // 3 seconds
if (msgId != null) {
console.log("Setting Match Option for MsgId");
gmo.MatchOptions = MQC.MQMO_MATCH_MSG_ID;
md.MsgId = hexToBytes(msgId);
}
// Set up the callback handler to be invoked when there
// are any incoming messages. As this is a sample, I'm going
// to tune down the poll interval from default 10 seconds to 0.5s.
// Also tune the polling to only get one message per attempt to
// to facilitate single shot async
mq.setTuningParameters({ getLoopPollTimeMs: 500, maxConsecutiveGets: 1 });
mq.Get(queueHandle, md, gmo, getCB);
}
setTimeout(() => {
// Resume processing second message
if (msgId2 != null) {
console.log("Setting Match Option for MsgId");
gmo.MatchOptions = MQC.MQMO_MATCH_MSG_ID;
md.MsgId = hexToBytes(msgId2);
}
mq.Get(hObj, md, gmo, getCB);
}, 2000 // Wait 2 seconds
)
if (myArgs[1]) {
qMgr = myArgs[1];
}
if (myArgs[2]) {
msgId = myArgs[2];
}
if (myArgs[3]) {
msgId2 = myArgs[3];
}
mq.setTuningParameters({ syncMQICompat: true });
// Connect to the queue manager, including a callback function for
// when it completes.
mq.Conn(qMgr, function (err, hConn) {
if (err) {
console.log(formatErr(err));
ok = false;
} else {
console.log("MQCONN to %s successful ", qMgr);
connectionHandle = hConn;
// Define what we want to open, and how we want to open it.
var od = new mq.MQOD();
od.ObjectName = qName;
od.ObjectType = MQC.MQOT_Q;
var openOptions = MQC.MQOO_INPUT_AS_Q_DEF;
mq.Open(hConn, od, openOptions, function (err, hObj) {
queueHandle = hObj;
if (err) {
console.log(formatErr(err));
function getMessage(hObj) {
var buf = Buffer.alloc(1024);
var mqmd = new mq.MQMD();
var gmo = new mq.MQGMO();
gmo.Options = MQC.MQGMO_NO_SYNCPOINT |
MQC.MQGMO_NO_WAIT |
MQC.MQGMO_CONVERT |
MQC.MQGMO_FAIL_IF_QUIESCING;
try {
var len = mq.GetSync(hObj,mqmd,gmo,buf);
var format = mqmd.Format;
// If the message has a DLH then
// parse and print it.
if (format == MQC.MQFMT_DEAD_LETTER_HEADER) {
var hdr = mq.MQDLH.getHeader(buf);
console.log("HDR is %j",hdr);
function cleanup(hConn,hObjPubQ, hObjSubscription) {
// Demonstrate two ways of closing queues - first using an exception, then
// the version with callback.
try {
mq.CloseSync(hObjSubscription,0);
console.log("MQCLOSE (Subscription) successful");
} catch (err) {
console.log("MQCLOSE (Subscription) ended with reason " + err);
}
mq.Close(hObjPubQ, 0, function(err) {
if (err) {
console.log("MQCLOSE (PubQ) ended with reason " + err.mqrc);
} else {
console.log("MQCLOSE (PubQ) successful");
}
mq.Disc(hConn, function(err) {
if (err) {
console.log("MQDISC ended with reason " + err.mqrc);
} else {
console.log("MQDISC successful");
}
});
});
}
function getMessages() {
var md = new mq.MQMD();
var gmo = new mq.MQGMO();
gmo.Options = MQC.MQGMO_NO_SYNCPOINT |
MQC.MQGMO_WAIT |
MQC.MQGMO_CONVERT |
MQC.MQGMO_FAIL_IF_QUIESCING;
gmo.MatchOptions = MQC.MQMO_NONE;
gmo.WaitInterval = waitInterval * 1000; // 3 seconds
if (msgId != null) {
console.log("Setting Match Option for MsgId");
gmo.MatchOptions = MQC.MQMO_MATCH_MSG_ID;
md.MsgId = hexToBytes(msgId);
}
// Set up the callback handler to be invoked when there
// are any incoming messages. As this is a sample, I'm going
function getMessage(hObj) {
var buf = Buffer.alloc(1024);
var mqmd = new mq.MQMD();
var gmo = new mq.MQGMO();
gmo.Options = MQC.MQGMO_NO_SYNCPOINT |
MQC.MQGMO_NO_WAIT |
MQC.MQGMO_CONVERT |
MQC.MQGMO_FAIL_IF_QUIESCING;
try {
var len = mq.GetSync(hObj,mqmd,gmo,buf);
var format = mqmd.Format;
// If the message has a DLH then
// parse and print it.
if (format == MQC.MQFMT_DEAD_LETTER_HEADER) {
var hdr = mq.MQDLH.getHeader(buf);
console.log("HDR is %j",hdr);
printMessage(hdr.Format,buf.slice(hdr.StrucLength),len-hdr.StrucLength);
Contributors:
Mark Taylor - Initial Contribution
*/
/*
* This is an example of a Node.js program to inquire about the attributes of an IBM MQ
* object.
*
* The queue manager name can be given as a parameter on the
* command line. Defaults are coded in the program.
*
*/
// Import the MQ package
var mq = require('ibmmq');
var MQC = mq.MQC; // Want to refer to this export directly for simplicity
// The queue manager to be used. This can be overridden on command line.
var qMgr = "QM1";
function formatErr(err) {
return "MQ call failed in " + err.message;
}
// When we're done, close queues and connections
function cleanup(hConn,hObj) {
mq.Close(hObj, 0, function(err) {
if (err) {
console.log(formatErr(err));
} else {
console.log("MQCLOSE successful");
mq.Connx(qMgr, cno, function(err,hConn) {
if (err) {
console.log(formatErr(err));
} else {
console.log("MQCONN to %s successful ", qMgr);
// Define what we want to open, and how we want to open it.
// In this case, we want to INQUIRE on attributes of the queue manager so we
// get an object handle that refers to that qmgr.
// No ObjectName is needed for this inquiry - the fact that it is the Q_MGR type
// is sufficient.
var od = new mq.MQOD();
od.ObjectName = null;
od.ObjectType = MQC.MQOT_Q_MGR;
var openOptions = MQC.MQOO_INQUIRE;
mq.Open(hConn,od,openOptions,function(err,hObj) {
if (err) {
console.log(formatErr(err));
} else {
console.log("MQOPEN of queue manager successful");
inqQmgr(hObj);
}
cleanup(hConn,hObj);
});
}
});