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

MQRC_CONNECTION_BROKEN [2009] error #164

Open gowrimech32 opened 1 year ago

gowrimech32 commented 1 year ago

I am calling the below node js script from our application.

var mq = require('ibmmq');

  module.exports = {  
    /**
      Check if it is possible to connect to the system using the given connection
     */
      validate: function (input, options, output) {

        var MQC = mq.MQC;
        var qMgr = "XXXXXXX";

        var cno = new mq.MQCNO();
        var csp = new mq.MQCSP();
        csp.UserId = "XXXXXX";
        csp.Password = "********";
        cno.SecurityParms = csp;

        cno.Options |= MQC.MQCNO_CLIENT_BINDING;

        var cd = new mq.MQCD();
        cd.ConnectionName = "XXXXXXXXXX";
        cd.ChannelName = "XXXXXXXX";
        cno.ClientConn = cd;

        mq.Connx(qMgr, cno, function(err,conn) {
          if (err) {
            logger.error(err);
            logger.error('MQ connection validation failed.')
            return output(err, {
              'result' : 'MQ connection validation failed.'
            })
          } else {
            logger.info('MQ connection validation successfully.')
              mq.Disc(conn, function(err) {
                if (err) {
                  logger.error("MQDISC failed");
                } else {
                  logger.info("MQDISC successful");
                }
              });
            return output(null, {
              'result': 'Connection validated successfully'
            })
          }
        });
      }
  }

The application user has access to Queue manager. If i run this method as a standalone script, it works fine. but if i run from application, then getting below error message.

CONNX: MQCC = MQCC_FAILED [2] MQRC = MQRC_CONNECTION_BROKEN [2009];MQCC_FAILED:2009;MQRC_CONNECTION_BROKEN

chughts commented 1 year ago

RE:

cno.Options |= MQC.MQCNO_CLIENT_BINDING;

Is your application running on the same machine as the queue manager?

gowrimech32 commented 1 year ago

No.... I am trying to connect queue manager which is running in different server.

chughts commented 1 year ago

That code, as you have already proven, should connect successfully. Which implies that your application is either not using the same code (add a check by logging something in that function that makes it clear that function is being invoked) or it is using it in a different way.

Your function validate takes in 3 arguments, but it is only using one - output. Is your application expecting validate to do something with input or options ?

gowrimech32 commented 1 year ago

I have already checked by adding loggers. It is invoking the function properly. I was getting below error. Then i solved it by copying the files from '/opt/mqm/lib64' to my application directory.

ENOENT: no such file or directory, open libmqm_r.so

After adding few more logger, i could see it is failing at below line.

libmqm.MQCONNX.async(mqqMgrName,mqCno.ref(), mqHConn,mqCc,mqRc, function (error,resp)

chughts commented 1 year ago

That seems to be your platform's equivalent to a LD_LIBRARY_PATH related issue.

From the README.md

For Windows and Linux x64, the npm installation process tries to access the Redistributable Client packages and unpack them automatically.

...

If you do not want this automatic installation of the MQ runtime, then set the environment variable MQIJS_NOREDIST to any value before running npm install. The MQ libraries are then be found at runtime using mechanisms such as searching LD_LIBRARY_PATH (Linux) or PATH (Windows).

By inference this automatic fetch of the redistributable client isn't performed on other platforms.

gowrimech32 commented 1 year ago

I could see same result after setting LD_LIBRARY_PATH

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/mqm/lib64

chughts commented 1 year ago

Check that the setting was inherited by the application by logging the value in your code.

eg.

debug_info("LD_LIBRARY_PATH : ", process.env.LD_LIBRARY_PATH);