ibm-messaging / mq-mqi-nodejs

Calling IBM MQ from Node.js - a JavaScript MQI wrapper
Apache License 2.0
79 stars 41 forks source link

how to find current queue depth of the mq ? i can connect the mq successfully but cant get the current queue depth #154

Closed jptech8 closed 1 year ago

jptech8 commented 1 year ago

var od = new mq.MQOD(); od.ObjectName = qName; od.ObjectType = MQC.MQOT_Q; var openOptions = 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);

        console.log(MQC.MQIA_CURRENT_Q_DEPTH)  
        console.log(MQC.MQTT_DEPTH) 
       console.log(od)
      //  getMessages(hObj);
fjbsaper commented 1 year ago

Why would you want to determine the number of messages in a queue before getting them. This is an anti-pattern. You should get all available messages until the error 2033 (no more messages matching criteria) is returned.

ibmmqmet commented 1 year ago

I don't know why you might think that simply opening a queue would return its depth.

As has already been said, trying to get the current depth of a queue is not usually a good idea. There can be specialised use cases when it's useful, and that's why the MQINQ verb (mq.Inq in this dialect) exists. See the amqsinq.js sample for how it is used.

jptech8 commented 1 year ago

Thanks for response . I can see some of the attributes in inq() returns the selector with value but not all the cases returns the value and throws selector error . MQRC SELCTOR_ERROR (2067) .Is there anyway to get MQIA_CURRENT_QUEUE_DEPTH ?

fjbsaper commented 1 year ago

Again, you have not specified what you need the queue depth for?

venky1993 commented 1 year ago

function inqQmgr(hObj) { // We will request 3 attributes of the queue manager. /* var selectors1 = [new mq.MQAttr(MQC.MQCA_Q_MGR_NAME), new mq.MQAttr(MQC.MQCA_DEAD_LETTER_Q_NAME), new mq.MQAttr(MQC.MQIA_CODED_CHAR_SET_ID) ];/

var selectors = [new mq.MQAttr(MQC.MQIA_CURRENT_Q_DEPTH)]

   try {
    mq.Inq(hObj,selectors);

    console.log(selectors)
    console.log(selectors[0].value)

   } catch (err) {
     console.log(err.message);
   }
}

// 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];
}

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;
    od.ObjectName = qName;
    od.ObjectType = MQC.MQOT_Q;
     var openOptions = MQC.MQOO_INQUIRE ;
    // var openOptions = MQC.MQOO_SET;

     mq.Open(hConn,od,openOptions,function(err,hObj) {
       if (err) {
         console.log(formatErr(err));
       } else {
         console.log("MQOPEN of queue manager successful",);
         console.log("hobj",hObj)
         inqQmgr(hObj)
        // setQ(hObj);

       }
       cleanup(hConn,hObj);
     });
   }
});
venky1993 commented 1 year ago

I am facing similar issue , When i tried to mention current queue depth to retrieve using mq.inq() i can see value is 2 but i dont feel its valid . Could you please check this snippet and help us .

ibmmqmet commented 1 year ago

I can't help you with why you feel the value is not valid. You've not given any clue as to what you think is wrong, or any output from other commands that indicate differently. 2 is a perfectly reasonable queue depth.

venky1993 commented 1 year ago

bingo same above code is working . Thanks all