Connecting to the MQ Server using CCDT

2019-03-03 12:18发布

I'm trying to connect to the MQ using the information present in the CCDT file. I can currently connect to the MQ using all the details, and get and put messages from and to the queue.

After extensive googling, I've been unable to find any sample code which allows me to connect using the CCDT file.

One of my colleagues forwarded me his JMS connection code, but I've been unable to port it to C#.

The JAVA code is as follows -

public class MQTest {
public static void main(String[] args) {

    MQQueueManager queueManager = null;
    URL ccdtFileUrl = null;
    MQMessage mqMessage = null;
    //MQPutMessageOptions myPMO = null
    try {
     String QM =    "IB9QMGR";
     String QUEUE1 = "TEST";

     System.out.println("Starting MQClient Put Program: ");
     ccdtFileUrl = new URL("file:///D:/AMQCLCHL.TAB") ;
     ccdtFileUrl.openConnection();
     queueManager = new MQQueueManager("SDCQMGR.T1", ccdtFileUrl);

     System.out.println("Connected to QMGR ");
     int openOptions = MQC.MQOO_OUTPUT;
     MQQueue InQueue = queueManager.accessQueue(QUEUE1,openOptions,null,null,null);
     MQMessage inMessage = new MQMessage();
     inMessage.writeString("###Testing####");
     InQueue.put(inMessage);
     System.out.println("Message Id is :" + inMessage.messageId);
     System.out.println(inMessage.toString());
     InQueue.close();
     queueManager.disconnect() ;
 }
 catch(MQException ex){
     System.out.println("MQ Error - Reason code :" + ex.reasonCode);
 }
 catch (Exception e){
     System.out.println("Error : " + e);
 }
}
}

Instead of URL, I used the URI (in C#) to set file location. (This may be wrongly used. Not sure what else to use though.)

Uri ccdtFileUrl = new Uri("file:///D:/AMQCLCHL.TAB") ;

but I can't use openConnection() on a URI. Also,

queueManager = new MQQueueManager("SDCQMGR.T1",ccdtFileUrl); gives an argument overload exception. As URI is not supported in C#.

I've tried looking up samples but I've found some JMS samples and thats it. Looking for some sample code to connect in C#.

标签: c# ibm-mq
1条回答
放我归山
2楼-- · 2019-03-03 12:32

You will need to set MQCHLLIB and MQCHLTAB environment variables to use CCDT. You can set these two variables either from command prompt,app.config or code in the application itself.

Following example demonstrates usage of CCDT:

        MQQueueManager qm = null;
        System.Environment.SetEnvironmentVariable("MQCHLLIB", "C:\\ProgramData\\IBM\\MQ\\qmgrs\\QM1\\@ipcc");
        System.Environment.SetEnvironmentVariable("MQCHLTAB", "AMQCLCHL.TAB");

        try
        {
            **Hashtable props = new Hashtable();
            props.Add(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES_CLIENT);
            qm = new MQQueueManager("QM1",props);**
            MQQueue queue1 = qm.AccessQueue("SYSTEM.DEFAULT.LOCAL.QUEUE", MQC.MQOO_OUTPUT | MQC.MQOO_FAIL_IF_QUIESCING);
            MQMessage msg = new MQMessage();
            msg.WriteUTF("Hello this message is from .net client");
            queue1.Put(msg);
            queue1.Close();
            qm.Disconnect();
        }
        catch (Exception ex)
        {
            Console.Write(ex);
        }
查看更多
登录 后发表回答