1

I'm making APIs with LoopBack( a Javascript Framework), pushing and getting messages with IBM MQ.

I followed this tut: Nodejs and MQ

I can do it with local Queue Manager, but I dont know how to connect to a remote Queue Manager.

So, can any one explain me how to do this ?

Tks all.

JoshMc
  • 10,239
  • 2
  • 19
  • 38
MiH
  • 409
  • 1
  • 4
  • 16
  • I dont know how to setup remote connection, because in code, it just set the QM name. I dont know how to specify the IP or hostname to the remote site – MiH Oct 12 '18 at 04:14
  • In the link you provided it talks about channel tables. – JoshMc Oct 12 '18 at 06:49
  • Can you explain me what exactly steps I need to do ? I'm new at this, so I dont know how do it. – MiH Oct 12 '18 at 08:00
  • 1
    Any of these methods will let you setup the client side to connect to a remote MQ server: [IBM Knowledge Center>IBM MQ 8.0.0>IBM MQ>Developing applications>Developing MQI applications with IBM MQ>Writing client procedural applications>Running applications in the IBM MQ MQI client environment>Connecting IBM MQ MQI client applications to queue managers](https://www.ibm.com/support/knowledgecenter/en/SSFKSJ_8.0.0/com.ibm.mq.dev.doc/q027440_.htm) – JoshMc Oct 12 '18 at 08:25
  • 1
    This sample on git shows how to specify the connection details as well: [ibm-messaging/mq-mqi-nodejs/samples/amqsconn.js](https://github.com/ibm-messaging/mq-mqi-nodejs/blob/master/samples/amqsconn.js) – JoshMc Oct 12 '18 at 08:34
  • Tks you very much! I'll try it – MiH Oct 12 '18 at 09:49

1 Answers1

0

I can do it with that link, which from @JoshMc's comment.

This is my code, it works fine:

module.exports = function (server) {
  var mq = require('ibmmq');
  var MQC = mq.MQC; // Want to refer to this export directly for simplicity

  // The queue manager and queue to be used. These can be overridden on command line.
  var qMgr = "QM1";
  var qName = "soa.log";
  var mqmd = new mq.MQMD(); // Defaults are fine.
  var pmo = new mq.MQPMO();
  var cd = new mq.MQCD();
  var cno = new mq.MQCNO();

  cd.ConnectionName = "localhost(1414)";
  cd.ChannelName = "CHAN1";
  var csp = new mq.MQCSP();

  cno.ClientConn = cd;  
  cno.Options = MQC.MQCNO_CLIENT_BINDING; // use MQCNO_CLIENT_BINDING to connect as client

  function putMessage(hObj) {
    var msg = Buffer.from(JSON.stringify(coff));
    // 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("MQPUT successful");
      }
    });
  }
  mq.Connx(qMgr, cno, function (err, hConn) {
    if (err) {
      console.log((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", qName);
          putMessage(hObj);
        }
       // cleanup(hConn, hObj);
      });
    }
  });
};
MiH
  • 409
  • 1
  • 4
  • 16