一切皆可抽象

大而无形 庖丁解牛 厚积薄发 涤虑玄览
   ::  ::  ::  ::  :: 管理

【原创】mq 的pcf使用

Posted on 2005-09-06 10:23 锋出磨砺 阅读(1057) 评论(0)  编辑  收藏 所属分类: 消息中间件

import com.ibm.mq.*;
import com.ibm.mq.pcf.*;

try
           {
                   PCFMessageAgent agent;
                   PCFMessage  request;
                   PCFMessage []  responses;
                   // Connect a PCFAgent to the specified queue manager


                   agent = new PCFMessageAgent ("channel1");
                   System.out.println ("DEFINE CONNECTION PARMENT....");


                   //agent = new PCFMessageAgent ("xxx");
                   //远程连接的试验一直没有作通,遗憾

                   //agent = new PCFMessageAgent ("channel1");        //本地channel1 是队列管理器的名字

                   //agent = new PCFMessageAgent ("MMM");
                  // SYSTEM.DEF.SVRCONN

                   System.out.println ("Connected.");
                   agent.setCharacterSet(1381);
                   // Build the PCF request


                  /**创建队列管理器   无法创建 没有提供创建命令
                   *
                   */


                   //创建通道

                   request = new PCFMessage (CMQCFC.MQCMD_CREATE_CHANNEL);
                   request.addParameter(CMQCFC.MQCACH_CHANNEL_NAME,"mama");
                   request.addParameter(CMQCFC.MQIACH_CHANNEL_TYPE,CMQXC.MQCHT_SVRCONN);

                   //request.addParameter(CMQCFC.MQIACH_CHANNEL_INSTANCE_TYPE,CMQXC.MQXPT_TCP);


                   //创建本地队列
                   /*
                  request = new PCFMessage (CMQCFC.MQCMD_CREATE_Q);
                  request.addParameter(CMQC.MQCA_Q_NAME,"tyty");
                  request.addParameter(CMQC.MQIA_Q_TYPE,CMQC.MQQT_LOCAL);
                  */
                 //创建进程
                  /*
                  request = new PCFMessage (CMQCFC.MQCMD_CREATE_PROCESS);
                  request.addParameter(CMQC.MQCA_PROCESS_NAME,"testtd");
                  request.addParameter(CMQC.MQCA_PROCESS_DESC,"tttt");
                  */

                   // Use the agent to send the request

                   System.out.print ("Sending PCF request... ");
                   //responses =  agent.send (request);
                   //查询队列
                   /*
                        request = new PCFMessage (CMQCFC.MQCMD_INQUIRE_Q_NAMES);
                        request.addParameter (CMQC.MQCA_Q_NAME, "*");
                        request.addParameter (CMQC.MQIA_Q_TYPE, MQC.MQQT_LOCAL);
                   */
                       responses = agent.send (request);
              /*
                       String []  names = (String []) responses [0].getParameterValue (CMQCFC.MQCACF_Q_NAMES);

         for (int i = 0; i < names.length; i++)
         {
                 System.out.println ("Queue: " + names [i]);
         }
          */

 

 

                   System.out.println ("Received reply.");
                   // Disconnect
                   System.out.print ("Disconnecting... ");
                   agent.disconnect ();
                   System.out.println ("Done.");
           }

           catch (ArrayIndexOutOfBoundsException abe)
           {
                   System.out.println ("Usage: \n" +
                           "\tjava PCFMessageListQManagerAttrs queue-manager\n" +
                           "\tjava PCFMessageListQManagerAttrs host port channel");
           }

           catch (NumberFormatException nfe)
           {
                   System.out.println ("Invalid port: " + args [1]);
                   System.out.println ("Usage: \n" +
                           "\tjava PCFMessageListQManagerAttrs queue-manager\n" +
                           "\tjava PCFMessageListQManagerAttrs host port channel");
           }

           catch (PCFException pcfe)
           {
                  // System.err.println ("Error in response: ");
                   //pcfe.printStackTrace();
                   PCFMessage []  responses = (PCFMessage []) pcfe.exceptionSource;

                   for (int i = 0; i < responses.length; i++)
                   {
                           System.out.println (responses [i]);
                   }
           }

           catch (MQException mqe)
           {
                   System.err.println (mqe);
                   mqe.printStackTrace();
           }

           catch (IOException ioe)
           {
                   System.err.println (ioe);
           }

      catch(Exception e)
           {
             e.printStackTrace();
           }


只有注册用户登录后才能发表评论。


网站导航: