Reputation: 4170
As a requirement of our partner, We have to make MQ connections on different ports. And the requirement is to configure separate CCDT files for each port because. All connections are made on one client application (one Process
).
Because our client application is one Process
I can't configure the below environment variables for each port separately.
How environment variables are set for configuring Client Channel Definition (This is .NET C#):
Environment.SetEnvironmentVariable("MQCHLLIB", @"C:\ProgramData\IBM\MQ");
Environment.SetEnvironmentVariable("MQCHLTAB", "AMQCLCHL<PORT>.TAB");
Our problem; We have to set these environment variables on connection level and not on Process or Global level. Any suggestions?
Update below is from info gathered in comments and Chat:
QMNAME(*)
.PORT
.Upvotes: 0
Views: 852
Reputation: 10652
Option 1 (This seems simpler if it works since you remove the need for CCDT which you are using because it was the only previously known way to specify compression options):
Based on a combination of documentation for both JMS and XMS I think the following may work, please try it, if this does not work then I will remove this from my answer, if it does work then I'll update with links to the mixture of documentation.
var factory = XMSFactoryFactory.GetInstance(XMSC.CT_WMQ);
var cf = factory.CreateConnectionFactory();
cf.SetStringProperty(XMSC.WMQ_HOST_NAME, host);
cf.SetIntProperty(XMSC.WMQ_PORT, port);
cf.SetStringProperty(XMSC.WMQ_CHANNEL, channel);
//empty string "" or "*" would work equally well for XMSC.WMQ_QUEUE_MANAGER to accept any queue manager name
cf.SetStringProperty(XMSC.WMQ_QUEUE_MANAGER, "");
cf.SetIntProperty(XMSC.WMQ_CONNECTION_MODE, XMSC.WMQ_CM_CLIENT_UNMANAGED);
cf.SetStringProperty(XMSC.WMQ_HEADER_COMP, "SYSTEM NONE");
cf.SetStringProperty(XMSC.WMQ_MSG_COMP, "ZLIBFAST ZLIBHIGH RLE NONE");
connection = cf.CreateConnection();
Option 2 directly specifying the CCDT locations to the XMSFactoryFactory and not relying on the environment variables:
Create the CF with a link to the CCDT directly instead of using Environment variables.
var factory = XMSFactoryFactory.GetInstance(XMSC.CT_WMQ);
var cf = factory.CreateConnectionFactory();
cf.SetIntProperty(XMSC.WMQ_CONNECTION_MODE, XMSC.WMQ_CM_CLIENT_UNMANAGED);
cf.SetStringProperty(XMSC.WMQ_CCDTURL, @"file://C:\ProgramData\IBM\MQ\AMQCLCHL<PORT>.TAB";
cf.SetStringProperty(XMSC.WMQ_QUEUE_MANAGER, "*");
connection = cf.CreateConnection();
Upvotes: 1
Reputation: 7476
Are you saying that once you start your application (process), it will connect & disconnect to/from different queue managers in one execution? If so, then setting the environment variables then changing them on the fly will not work.
A better approach is to have an INI file with 4 sections - 1 per port. Have your application load the particular section from the INI file, create a Hashtable with those particular values and pass the Hashtable to the MQQueueManager class.
For more information about reading an INI file see: https://code.msdn.microsoft.com/windowsdesktop/Reading-and-Writing-Values-85084b6a
I would set your 1414 section of the INI file as:
[Port1414]
mq.qmname=MQA1
mq.channel=TEST.CHL
mq.hostname=10.10.10.10
mq.port=1414
mq.userid=MyUserId
mq.inputq=SOME.INPUT.QUEUE
mq.outputq=SOME.OUTPUT.QUEUE
And for 1415 section of the INI file as:
[Port1415]
mq.qmname=MQA1
mq.channel=TEST.CHL
mq.hostname=10.10.10.10
mq.port=1415
mq.userid=MyUserId
mq.inputq=SOME.INPUT.QUEUE2
mq.outputq=SOME.OUTPUT.QUEUE2
and the same for the 1415 & 1416.
After reading the particular section of the INI file, you would do:
Hashtable qMgrProp = new Hashtable();
qMgrProp.Add(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES_MANAGED);
qMgrProp.Add(MQC.CHANNEL_PROPERTY, channelName);
qMgrProp.Add(MQC.HOST_NAME_PROPERTY, hostname);
qMgrProp.Add(MQC.PORT_PROPERTY, 1414);
qMgrProp.Add(MQC.USER_ID_PROPERTY, userId);
MQQueueManager qMgr = new MQQueueManager(qManager, qMgrProp);
Upvotes: 1