jcamposgranado
jcamposgranado

Reputation: 11

Connect to multiple queue managers in different servers

I am trying to connect a C++ application (using MQCONNX) based on a PaaS IBM MQ client to two different queue managers, each one based on a different server (one in a PaaS server and the other one in a Unix server). Unfortunately I am not able to do it as I am getting a message when I try to connect to the second server saying that it is not possible as it is connected to the first queue manager. I am using two different MQHCONN connections, one for each queue manager, but the problem is still there.

I have taken a look into this link, but I still have some doubts, as for example, from which server should I copy the CCDT to the client?

https://www.ibm.com/support/pages/connecting-mq-clients-multiple-queue-managers-client-channel-definition-table-ccdt

Any help would be much appreciated, or even a quick sample of how to use CCDT, as right now I am completely stuck.

Many thanks in advance for any help.

Upvotes: 0

Views: 599

Answers (1)

Morag Hughson
Morag Hughson

Reputation: 7525

Assuming Queue Manager 1 is called MQG1 and Queue Manager 2 is called MQG2 and these can be found using connection names of machine1.com(1701) and machine2.com(1702) respectively, and using channel names MQG1.SVRCONN and MQG2.SVRCONN respectively, you can create your CCDT, on your client application machine, thus:-

runmqsc -n

issue these commands into runmqsc:-

DEFINE CHANNEL(MQG1.SVRCONN) CHLTYPE(CLNTCONN) CONNAME('machine1.com(1701)') QMNAME(MQG1)
DEFINE CHANNEL(MQG2.SVRCONN) CHLTYPE(CLNTCONN) CONNAME('machine2.com(1702)') QMNAME(MQG2)

Then you can code your 2 x MQCONN (or MQCONNX if you need to specify any additional things on the connection) thus:-

#include <cmqc.h>                    /* Includes for MQI constants */
#include <cmqstrc.h>                 /* Convert MQRC into string   */

MQHCONN hConn1 = MQHC_UNUSABLE_HCONN;
MQHCONN hConn2 = MQHC_UNUSABLE_HCONN;
MQCHAR  QMName1[MQ_Q_MGR_NAME_LENGTH] = "MQG1";
MQCHAR  QMName2[MQ_Q_MGR_NAME_LENGTH] = "MQG2";
MQLONG  CompCode, Reason;

MQCONN(QMName1,
       &hConn1,
       &CompCode,
       &Reason);
if (CompCode)
{
  printf("MQCONN to %s failed with reason code %s (%d)\n", QMName1, MQRC_STR(Reason), Reason); 
}
MQCONN(QMName2,
       &hConn2,
       &CompCode,
       &Reason);
if (CompCode)
{
  printf("MQCONN to %s failed with reason code %s (%d)\n", QMName2, MQRC_STR(Reason), Reason); 
}

Take care with how you are linking your program. If you try to make two local connections, you will get a return code of MQRC_ANOTHER_Q_MGR_CONNECTED. Ensure you either link with the client library, set connection option MQCNO_CLIENT (which means you must use MQCONNX) or set the environment variable MQ_CONNECT_TYPE=CLIENT.

You might find the following blog post useful additional reading:-

IBM MQ Little Gem #30: MQ_CONNECT_TYPE

Upvotes: 2

Related Questions