Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function putMessage(hObj) {
var msg = "Hello from Node at " + new Date();
var mqmd = new mq.MQMD(); // Defaults are fine.
var pmo = new mq.MQPMO();
// Describe how the Put should behave
pmo.Options = MQC.MQPMO_NO_SYNCPOINT |
MQC.MQPMO_NEW_MSG_ID |
MQC.MQPMO_NEW_CORREL_ID;
mq.Put(hObj,mqmd,pmo,msg,function(err) {
if (err) {
console.log(formatErr(err));
} else {
console.log("MsgId: " + toHexString(mqmd.MsgId));
console.log("MQPUT successful");
}
});
}
function publishMessage(hObj) {
var msg = "Hello from Node at " + new Date();
var mqmd = new mq.MQMD(); // Defaults are fine.
var pmo = new mq.MQPMO();
// Describe how the Publish (Put) should behave
pmo.Options = MQC.MQPMO_NO_SYNCPOINT |
MQC.MQPMO_NEW_MSG_ID |
MQC.MQPMO_NEW_CORREL_ID;
// Add in the flag that gives a warning if noone is
// subscribed to this topic.
pmo.Options |= MQC.MQPMO_WARN_IF_NO_SUBS_MATCHED;
mq.Put(hObj,mqmd,pmo,msg,function(err) {
if (err) {
console.error(formatErr(err));
} else {
console.log("MQPUT successful");
}
});
}
// scratch) then we need to say up front what type it is.
mqmd.Format = MQC.MQFMT_STRING;
// Create a DLH and allow it to modify MQMD chaining fields like the CCSID
var mqdlh = new mq.MQDLH(mqmd);
// Fill in something for why the message is put to the DLQ
mqdlh.Reason = MQC.MQRC_NOT_AUTHORIZED;
mqdlh.DestQName = "DEST.QUEUE";
mqdlh.DestQMgrName = "DEST.QMGR";
// Create the full message by concatenating buffers into a single block
var fullMsg = Buffer.concat([mqdlh.getBuffer(),Buffer.from(msg)]);
// And put the message
mq.Put(hObj,mqmd,pmo,fullMsg,function(err) {
if (err) {
console.log(formatErr(err));
} else {
console.log("MQPUT successful");
}
});
}
'value': Math.floor(Math.random() * 100)
}
var msg = JSON.stringify(msgObject);
var mqmd = new mq.MQMD(); // Defaults are fine.
mqmd.ReplyToQ = hObjDynamic._name;
mqmd.MsgType = MQC.MQMT_REQUEST;
var pmo = new mq.MQPMO();
// Describe how the Put should behave
pmo.Options = MQC.MQPMO_NO_SYNCPOINT |
MQC.MQPMO_NEW_MSG_ID |
MQC.MQPMO_NEW_CORREL_ID;
mq.Put(hObj, mqmd, pmo, msg, function(err) {
if (err) {
debug_warn('Error Detected in Put operation', err);
cb(err, null);
} else {
var msgId = toHexString(mqmd.MsgId);
debug_info('MsgId: ', msgId);
debug_info("MQPUT successful");
cb(null, msgId);
}
});
}
var msgObject = {
'Greeting': "Hello from Node at " + new Date()
}
var msg = JSON.stringify(msgObject);
var mqmd = new mq.MQMD(); // Defaults are fine.
var pmo = new mq.MQPMO();
// Describe how the Publish (Put) should behave
pmo.Options = MQC.MQPMO_NO_SYNCPOINT |
MQC.MQPMO_NEW_MSG_ID |
MQC.MQPMO_NEW_CORREL_ID;
// Add in the flag that gives a warning if noone is
// subscribed to this topic.
pmo.Options |= MQC.MQPMO_WARN_IF_NO_SUBS_MATCHED;
mq.Put(hObj, mqmd, pmo, msg, function(err) {
if (err && 'object' === typeof err && err.mqrc &&
MQC.MQRC_NO_SUBS_MATCHED == err.mqrc && err.mqrcstr) {
debug_info('Publish unsuccessful because there are no subscribers', err.mqrcstr);
} else if (err) {
debug_warn('Error Detected in Put operation', err);
} else {
debug_info('MsgId: ', toHexString(mqmd.MsgId));
debug_info("MQPUT for Publish successful");
}
});
}
debug_info('Inside MQ Open for Reply Callback function');
if (err) {
debug_warn('Error Detected Opening MQ Connection for Reply', err);
} else {
debug_info("MQOPEN of %s successful", mqmdRequest.ReplyToQMgr);
var mqmd = new mq.MQMD(); // Defaults are fine.
var pmo = new mq.MQPMO();
mqmd.CorrelId = mqmdRequest.CorrelId;
mqmd.MsgId = mqmdRequest.MsgId;
// Describe how the Put should behave
pmo.Options = MQC.MQPMO_NO_SYNCPOINT;
mq.Put(hObjReply, mqmd, pmo, msg, function(err) {
if (err) {
debug_warn('Error Detected in Put operation', err);
} else {
debug_info('MsgId: ', toHexString(mqmd.MsgId));
debug_info("MQPUT successful");
}
});
}
});