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(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);
} else {
printMessage(format,buf,len);
}
} catch (err) {
if (err.mqrc == MQC.MQRC_NO_MSG_AVAILABLE) {
console.log("no more messages");
} else {
console.log(formatErr(err));
function getMessage(hObj) {
var buf = Buffer.alloc(1024);
var mqmd = new mq.MQMD();
var gmo = new mq.MQGMO();
gmo.WaitInterval = 3 * 1000; // 3 seconds
gmo.Options = MQC.MQGMO_NO_SYNCPOINT |
MQC.MQGMO_WAIT |
MQC.MQGMO_CONVERT |
MQC.MQGMO_FAIL_IF_QUIESCING;
mq.GetSync(hObj,mqmd,gmo,buf,function(err,len) {
if (err) {
if (err.mqrc == MQC.MQRC_NO_MSG_AVAILABLE) {
console.log("no more messages");
} else {
console.log("MQGET failed with " + err.mqrc);
}
ok = false;
} else {
if (mqmd.Format=="MQSTR") {
console.log("message <%s>", decoder.write(buf.slice(0,len)));
} else {
console.log("binary message: " + buf);
}
}
});
}
return new Promise(function resolver(resolve, reject) {
let buf = Buffer.alloc(1024);
let mqmd = new mq.MQMD();
let gmo = new mq.MQGMO();
gmo.Options = MQC.MQGMO_NO_SYNCPOINT |
MQC.MQGMO_NO_WAIT |
MQC.MQGMO_CONVERT |
MQC.MQGMO_FAIL_IF_QUIESCING;
mq.GetSync(hObj, mqmd, gmo, buf, function(err, len) {
if (err) {
if (err.mqrc == MQC.MQRC_NO_MSG_AVAILABLE) {
debug_info("no more messages");
} else {
debug_warn('Error retrieving message', err);
}
debug_info('Returning false from getMessage');
resolve(false);
} else if (mqmd.Format == "MQSTR") {
// The Message from a Synchronouse GET is
// a data buffer, which needs to be encoded
// into a string, before the underlying
// JSON object is extracted.
// The stringify step is needed to truncate
// the unitialised / empty part of the buffer.
let buffString = JSON.stringify(buf.toString('utf8'));
function getMessage(hConn, hObj) {
var buf = Buffer.alloc(1024, 0);
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;
mq.GetSync(hObj, mqmd, gmo, buf, function(err, len) {
if (err) {
if (err.mqrc == MQC.MQRC_NO_MSG_AVAILABLE) {
debug_info("no more messages");
} else {
debug_warn('Error retrieving message', err);
}
ok = false;
} else if (mqmd.Format == "MQSTR") {
var msgObject = null;
// The Message from a Synchronouse GET is
// a data buffer, which needs to be encoded
// into a string, before the underlying
// JSON object is extracted.
// The stringify step is needed to truncate
// the unitialised / empty part of the buffer.
function getMessage(hObj) {
var buf = Buffer.alloc(1024);
var hdr;
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;
mq.GetSync(hObj,mqmd,gmo,buf,function(err,len) {
if (err) {
if (err.mqrc == MQC.MQRC_NO_MSG_AVAILABLE) {
console.log("no more messages");
} else {
console.log(formatErr(err));
}
ok = false;
} else {
var format = mqmd.Format;
switch (format) {
case MQC.MQFMT_RF_HEADER_2:
hdr = mq.MQRFH2.getHeader(buf);
var props = mq.MQRFH2.getProperties(hdr,buf);
console.log("RFH2 HDR is %j",hdr);
console.log("Properties are '%s'",props);
printBody(hdr.Format,buf.slice(hdr.StrucLength),len-hdr.StrucLength);