×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

receive message from IBM MQ in js app

receive message from IBM MQ in js app

receive message from IBM MQ in js app

(OP)
Hi! I need to receive messages from IBM MQ in a js app.
The goal is:
1. Receive a message
2. Make several operations with date
3. When all operations are finished, make the same with the second message.

I face a problem. The await isn't worked. And I receive all messages and can't work in the "synchronic style" one after one.

const mq = require("ibmmq");
const { loadBaselineFile, dbStatus } = require("./dbLoader");
const dbl = require("./dbLoader");

const logger = require("../config/logerConfig");
const fs = require("fs");
const MQC = mq.MQC;

const StringDecoder = require("string_decoder").StringDecoder;
const decoder = new StringDecoder("utf8");

const qMgr = "QM1";
const qName = "TEST.QUEUE";
const msgId = null;

let connectionHandle;
let queueHandle;
let count = 0;

module.exports = { startListeningMQ };
function startListeningMQ() {
const cno = new mq.MQCNO();

const csp = new mq.MQCSP();
csp.UserId = "mqm";
csp.Password = "mqm";
cno.SecurityParms = csp;

cno.Options |= MQC.MQCNO_CLIENT_BINDING;
const cd = new mq.MQCD();
cd.ConnectionName = "localhost(1414)";
cd.ChannelName = "SVRCONN";
cno.ClientConn = cd;

mq.Conn(qMgr, function(err, hConn) {
if (err) {
console.log(formatErr(err));
} else {
console.log("MQCONN to %s successful ", qMgr);
connectionHandle = hConn;

const od = new mq.MQOD();
od.ObjectName = qName;
od.ObjectType = MQC.MQOT_Q;
const openOptions = MQC.MQOO_BROWSE;
mq.Open(hConn, od, openOptions, function(err, hObj) {
queueHandle = hObj;
if (err) {
console.log(formatErr(err));
} else {
console.log("MQOPEN of %s successful", qName);
getMessages();
}
});
}
});
}

function getMessages() {
const md = new mq.MQMD();
const gmo = new mq.MQGMO();

gmo.Options =
MQC.MQGMO_NO_SYNCPOINT |
MQC.MQGMO_WAIT |
MQC.MQGMO_CONVERT |
MQC.MQGMO_FAIL_IF_QUIESCING |
MQC.MQGMO_MQWI_UNLIMITED;
gmo.Options |= MQC.MQGMO_BROWSE_NEXT;

gmo.MatchOptions = MQC.MQMO_NONE;

if (msgId != null) {
console.log("Setting Match Option for MsgId");
gmo.MatchOptions = MQC.MQMO_MATCH_MSG_ID;
md.MsgId = hexToBytes(msgId);
}

mq.setTuningParameters({ getLoopPollTimeMs: 500 });
mq.Get(queueHandle, md, gmo, getCB);
}

function hexToBytes(hex) {
for (const bytes = [], c = 0; c < hex.length; c += 2)
bytes.push(parseInt(hex.substr(c, 2), 16));
return bytes;
}

async function getCB(err, hObj, gmo, md, buf, hConn) {
if (err) {
if (err.mqrc == MQC.MQRC_NO_MSG_AVAILABLE) {
console.log("No more messages available.");
} else {
console.log(formatErr(err));
exitCode = 1;
}
ok = false;
mq.GetSync(hObj);
} else {
if (md.Format == "MQSTR") {
console.log("message <%s>", decoder.write(buf));
count++;
try {
fs.writeFileSync(
"data_loader/dataForLoad/tryAgain" + count + ".json",
decoder.write(buf),
"utf8"
);
} catch (e) {
console.log("Cannot write file ", e);
}

const filePath =
`file:///home` +
`myfile.json`;
logger.serverLogger().info(`Start to upload BASELINE file ${filePath}`);


await MYFUNCTION(filePath);
gmo.Options &= ~MQC.MQGMO_BROWSE_FIRST;
gmo.Options |= MQC.MQGMO_BROWSE_NEXT;

} else {
console.log("binary message: " + buf);
}
}
}

function formatErr(err) {
if (err) {
ok = false;
return "MQ call failed at " + err.message;
} else {
return "MQ call successful";
}
}

function sleep {
setTimeout(function() {}, ms);
}

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close