本文介绍了使用CCDT连接到MQ服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用CCDT文件中提供的信息连接到MQ.我目前可以使用所有详细信息连接到MQ,并从队列中获取消息并将消息放入队列.

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.

广泛搜索之后,我找不到任何允许使用CCDT文件进行连接的示例代码.

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

我的一位同事向我转发了他的JMS连接代码,但是我无法将其移植到C#.

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

JAVA代码如下-

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

我使用URI(在C#中)而不是URL来设置文件位置. (这可能被错误地使用.虽然不确定还可以使用什么.)

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

,但是我不能在URI上使用openConnection().另外,

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

queueManager = new MQQueueManager("SDCQMGR.T1",ccdtFileUrl); 给出一个参数重载异常.由于C#不支持URI.

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

我尝试查找样本,但是我发现了一些JMS样本,仅此而已.寻找一些示例代码以在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#.

推荐答案

您将需要设置MQCHLLIBMQCHLTAB环境变量才能使用CCDT.您可以从命令提示符app.config或应用程序本身中的代码中设置这两个变量.

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.

下面的示例演示CCDT的用法:

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

这篇关于使用CCDT连接到MQ服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 04:31