Connecting to the MQ Server using CCDT

萝らか妹 提交于 2019-12-02 16:34:55

问题


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#.


回答1:


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);
        }


来源:https://stackoverflow.com/questions/26092251/connecting-to-the-mq-server-using-ccdt

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!