Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// First force the client mode
cno.Options |= MQC.MQCNO_CLIENT_BINDING;
// And then fill in relevant fields for the MQCD
var cd = new mq.MQCD();
cd.ConnectionName = "localhost(1414)";
cd.ChannelName = "SYSTEM.DEF.SVRCONN";
// Make the MQCNO refer to the MQCD
cno.ClientConn = cd;
// MQ V9.1.2 allows setting of the application name explicitly
if (MQC.MQCNO_CURRENT_VERSION >= 7) {
cno.ApplName = "Node.js 9.1.2 ApplName";
}
// Now we can try to connect
mq.Connx(qMgr, cno, function(err,conn) {
if (err) {
console.log(formatErr(err));
} else {
console.log("MQCONN to %s successful ", qMgr);
// Sleep for a few seconds - bad in a real program but good for this one
sleep(3 *1000).then(() => {
mq.Disc(conn, function(err) {
if (err) {
console.log(formatErr(err));
} else {
console.log("MQDISC successful");
}
});
});
}
});
console.log("Sample AMQSPROP.JS start");
// Get command line parameters
var myArgs = process.argv.slice(2); // Remove redundant parms
if (myArgs[0]) {
qName = myArgs[0];
}
if (myArgs[1]) {
qMgr = myArgs[1];
}
var cno = new mq.MQCNO();
cno.Options = MQC.MQCNO_NONE;
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.
var od = new mq.MQOD();
od.ObjectName = qName;
od.ObjectType = MQC.MQOT_Q;
var openOptions = MQC.MQOO_OUTPUT | MQC.MQOO_INPUT_AS_Q_DEF;
mq.Open(hConn,od,openOptions,function(err,hObj) {
if (err) {
console.log(formatErr(err));
} else {
console.log("MQOPEN of %s successful",qName);
putMessage(hConn,hObj);
// The program really starts here.
// Connect to the queue manager. If that works, the callback function
// opens the queue manager for inquiry, and then we can do the real query.
console.log("Sample AMQSINQ.JS start");
// Get command line parameters
var myArgs = process.argv.slice(2); // Remove redundant parms
if (myArgs[0]) {
qMgr = myArgs[0];
}
var cno = new mq.MQCNO();
cno.Options = MQC.MQCNO_NONE;
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) {
// The location of the KeyRepository is not specified in the CCDT, so regardless
// of whether a CCDT is being used, need to specify the KeyRepository location
// if it has been provided in the environment json settings.
if (MQDetails.KEY_REPOSITORY) {
debug_info('Key Repository has been specified');
// *** For TLS ***
var sco = new mq.MQSCO();
sco.KeyRepository = MQDetails.KEY_REPOSITORY;
// And make the CNO refer to the SSL Connection Options
cno.SSLConfig = sco;
}
// Do the connect, including a callback function
mq.Connx(MQDetails.QMGR, cno, function(err, hConn) {
if (err) {
console.log("MQCONN ended with reason code " + err.mqrc);
} else {
console.log("MQCONN to %s successful ", MQDetails.QMGR);
// Define what we want to open, and how we want to open it.
var sd = new mq.MQSD();
sd.ObjectString = MQDetails.TOPIC_NAME;
sd.Options = MQC.MQSO_CREATE |
MQC.MQSO_NON_DURABLE |
MQC.MQSO_FAIL_IF_QUIESCING |
MQC.MQSO_MANAGED;
mq.Sub(hConn, null, sd, function(err, hObjPubQ, hObjSubscription) {
if (err) {
debug_warn("MQSUB ended with reason " + err.mqrc);
console.log("Sample AMQSDLH.JS start");
// Get command line parameters
var myArgs = process.argv.slice(2); // Remove redundant parms
if (myArgs[0]) {
qName = myArgs[0];
}
if (myArgs[1]) {
qMgr = myArgs[1];
}
var cno = new mq.MQCNO();
cno.Options = MQC.MQCNO_NONE; // use MQCNO_CLIENT_BINDING to connect as client
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.
var od = new mq.MQOD();
od.ObjectName = qName;
od.ObjectType = MQC.MQOT_Q;
var openOptions = MQC.MQOO_OUTPUT | MQC.MQOO_INPUT_AS_Q_DEF;
mq.Open(hConn,od,openOptions,function(err,hObj) {
if (err) {
console.log(formatErr(err));
} else {
console.log("MQOPEN of %s successful",qName);
// Assume queue is empty when we start
if (myArgs[1]) {
qMgr = myArgs[1];
}
var cno = new mq.MQCNO();
cno.Options = MQC.MQCNO_NONE; // use MQCNO_CLIENT_BINDING to connect as client
// To add authentication, enable this block
if (false) {
var csp = new mq.MQCSP();
csp.UserId = "metaylor";
csp.Password = "passw0rd";
cno.SecurityParms = csp;
}
mq.Connx(qMgr, cno, function(err,hConn) {
if (err) {
console.error(formatErr(err));
} else {
console.log("MQCONN to %s successful ", qMgr);
// Define what we want to open, and how we want to open it.
//
// For this sample, we use only the ObjectString, though it is possible
// to use the ObjectName to refer to a topic Object (ie something
// that shows up in the DISPLAY TOPIC list) and then that
// object's TopicStr attribute is used as a prefix to the TopicString
// value supplied here.
// Remember that the combined TopicString attribute has to match what
// the subscriber is using.
var od = new mq.MQOD();
od.ObjectString = topicString;
// The location of the KeyRepository is not specified in the CCDT, so regardless
// of whether a CCDT is being used, need to specify the KeyRepository location
// if it has been provided in the environment json settings.
if (MQDetails.KEY_REPOSITORY) {
debug_info('Key Repository has been specified');
// *** For TLS ***
var sco = new mq.MQSCO();
sco.KeyRepository = MQDetails.KEY_REPOSITORY;
// And make the CNO refer to the SSL Connection Options
cno.SSLConfig = sco;
}
// Do the connect, including a callback function
mq.Connx(MQDetails.QMGR, cno, function(err, hConn) {
if (err) {
debug_warn('Error Detected making Connection', err);
} else {
debug_info("MQCONN to %s successful ", MQDetails.QMGR);
// Define what we want to open, and how we want to open it.
var od = new mq.MQOD();
od.ObjectName = MQDetails.QUEUE_NAME;
od.ObjectType = MQC.MQOT_Q;
var openOptions = MQC.MQOO_INPUT_AS_Q_DEF;
mq.Open(hConn, od, openOptions, function(err, hObj) {
if (err) {
debug_warn('Error Detected Opening MQ Connection', err);
} else {
debug_info("MQOPEN of %s successful", MQDetails.QUEUE_NAME);
// And loop getting messages until done.
getMessages(hConn, hObj);
// The location of the KeyRepository is not specified in the CCDT, so regardless
// of whether a CCDT is being used, need to specify the KeyRepository location
// if it has been provided in the environment json settings.
if (MQDetails.KEY_REPOSITORY) {
debug_info('Key Repository has been specified');
// *** For TLS ***
var sco = new mq.MQSCO();
sco.KeyRepository = MQDetails.KEY_REPOSITORY;
// And make the CNO refer to the SSL Connection Options
cno.SSLConfig = sco;
}
debug_info('Attempting Connection to MQ Server');
mq.Connx(MQDetails.QMGR, cno, function(err, hConn) {
debug_info('Inside Connection Callback function');
if (err) {
debug_warn('Error Detected making Connection', err);
} else {
debug_info("MQCONN to %s successful ", MQDetails.QMGR);
// Define what we want to open, and how we want to open it.
var od = new mq.MQOD();
od.ObjectName = MQDetails.QUEUE_NAME;
od.ObjectType = MQC.MQOT_Q;
var openOptions = MQC.MQOO_OUTPUT;
mq.Open(hConn, od, openOptions, function(err, hObj) {
debug_info('Inside MQ Open Callback function');
if (err) {
debug_warn('Error Detected Opening MQ Connection', err);
// The location of the KeyRepository is not specified in the CCDT, so regardless
// of whether a CCDT is being used, need to specify the KeyRepository location
// if it has been provided in the environment json settings.
if (MQDetails.KEY_REPOSITORY) {
debug_info('Key Repository has been specified');
// *** For TLS ***
var sco = new mq.MQSCO();
sco.KeyRepository = MQDetails.KEY_REPOSITORY;
// And make the CNO refer to the SSL Connection Options
cno.SSLConfig = sco;
}
debug_info('Attempting Connection to MQ Server');
mq.Connx(MQDetails.QMGR, cno, function(err, hConn) {
debug_info('Inside Connection Callback function');
if (err) {
debug_warn('Error Detected making Connection', err);
} else {
debug_info("MQCONN to %s successful ", MQDetails.QMGR);
// Open up the Dynamic Response queue
var odDynamic = new mq.MQOD();
odDynamic.ObjectName = MQDetails.MODEL_QUEUE_NAME;
odDynamic.DynamicQName = MQDetails.DYNAMIC_QUEUE_PREFIX;
var openDynamicOptions = MQC.MQOO_INPUT_EXCLUSIVE;
//var openDynamicOptions = null;
mq.Open(hConn, odDynamic, openDynamicOptions, function(err, hObjDynamic) {
debug_info('Inside MQ Open Dynamic Queue Callback function');
return new Promise(function resolver(resolve, reject){
debug_info('Performing Connx');
// Do the connect, including a callback function
mq.Connx(MQDetails.QMGR, cno, function(err, hConn) {
if (err) {
debug_warn('Error Detected making Connection', err);
reject();
} else {
debug_info("MQCONN to %s successful ", MQDetails.QMGR);
resolve(hConn);
}
});
});
}