You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I'm trying use node js and express to implement a restful service to put message to IBM MQ,
here is my code:
const express = require( "express" );
const app = express();
const port = 8050; // default port to listen
const mq = require( "ibmmq" );
function formatErr(err) {
return "MQ call failed in " + err.message;
}
function sleep(ms) {
return new Promise(resolve=![image](https://user-images.githubusercontent.com/11471535/120274900-19bb4480-c2e3-11eb-9646-13fc345fdbd5.png){
setTimeout(resolve,ms);
});
}
function toHexString(byteArray) {
return byteArray.reduce((output, elem) =>
(output + ('0' + elem.toString(16)).slice(-2)),
'');
}
function putMessage(hObj) {
var msg = "Hello from Node at " + new Date();
console.log("putMessage start!");
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 cleanup(hConn,hObj) {
mq.Close(hObj, 0, function(err) {
if (err) {
console.log(formatErr(err));
} else {
console.log("MQCLOSE successful");
}
mq.Disc(hConn, function(err) {
if (err) {
console.log(formatErr(err));
} else {
console.log("MQDISC successful");
}
});
});
}
// define a route handler for the default home page
app.get( "/", ( req, res ) => {
var MQC = mq.MQC;
var qMgr = "QM1";
var qName = "DEV.QUEUE.1";
var hConn;
var cno = new mq.MQCNO();
cno.Options |= MQC.MQCNO_CLIENT_BINDING;
var cd = new mq.MQCD();
cd.ConnectionName = "localhost(1414)";
cd.ChannelName = "DEV.APP.SVRCONN";
cno.ClientConn = cd;
var csp = new mq.MQCSP();
csp.UserId = "app";
csp.Password = "ssssssss";
cno.SecurityParms = csp;
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;
mq.Open(hConn,od,openOptions,function(err,hObj) {
if (err) {
console.log(formatErr(err));
} else {
console.log("MQOPEN of %s successful",hObj);
putMessage(hObj);
}
cleanup(hConn,hObj);
});
}
});
// res.send( "Hello world!" );
} );
// start the Express server
app.listen( port, () => {
console.log( `server started at http://localhost:${ port }` );
} );
The server started ok:
but will get error code and exit with put function.
Here is the server debug.log:
Is anything wrong with this case?
The text was updated successfully, but these errors were encountered:
ginlo0628
changed the title
fail to put message
fail to put message with express
Jun 1, 2021
Hi, I'm trying use node js and express to implement a restful service to put message to IBM MQ,
here is my code:
The server started ok:
but will get error code and exit with put function.
Here is the server debug.log:
Is anything wrong with this case?
The text was updated successfully, but these errors were encountered: