2016-09-22 88 views
-1

我正在使用Web球體版本7.5,是否需要系統代理啓動MQ服務。當我通過Java代碼訪問時,如何啓動MQ服務。目前,我得到以下例外通過代碼如何啓動Websphere Mq服務?

MQJE001訪問時:一個的MQException發生:完成碼2,原因是2009年 MQJE016:MQ隊列管理器在連接過程中 關閉原因立即關閉通道= 2009

MQJE001:一個的MQException發生:完成碼2,原因2009 MQJE016:MQ隊列管理器在連接過程中 封閉原因立即關閉通道= 2009

com.ibm.mq.MQException:MQJE001:一個的MQException發生:完成碼2,2009年原因

MQJE016:MQ隊列管理器在連接過程中 封閉原因立即關閉通道= 2009

我使用的代碼如下

public class Demo { 
      private MQQueueManager _queueManager = null; 
      public int port = 1422; 
      public String hostname = "192.168.1.5";//IP OF HOST 
      public String channel = "QM_ORANGE.QM_APPLE";//channel name 
      public String qManager = "QM_ORANGE";//queue manager name 
      public String inputQName = "Q1";//remote q type 
      public String outputQName = "QM_APPLE";//queue manager 

      public Demo() { 
       super(); 
      } 

      private void init(String[] args) throws IllegalArgumentException { 
       // Set up MQ environment 
       MQEnvironment.hostname = hostname; 
       MQEnvironment.channel = channel; 
       MQEnvironment.port = port; 
      } 

      public static void main(String[] args) { 

       Demo readQ = new Demo(); 

       try { 
        readQ.init(args); 
        readQ.selectQMgr(); 
        readQ.read(); 
        readQ.write(); 
       } catch (IllegalArgumentException e) { 
        System.out 
          .println("Usage: java MQRead <-h host> <-p port> <-c channel> <-m QueueManagerName> <-q QueueName>"); 
        System.exit(1); 
       } catch (MQException e) { 
        System.out.println(e); 
        System.exit(1); 
       } 
      } 

      private void read() throws MQException { 
       int openOptions = MQC.MQOO_INQUIRE + MQC.MQOO_FAIL_IF_QUIESCING 
         + MQC.MQOO_INPUT_SHARED; 

       MQQueue queue = _queueManager.accessQueue(inputQName, openOptions, 
         null, // default q manager 
         null, // no dynamic q name 
         null); // no alternate user id 

       System.out.println("MQRead v1.0 connected.\n"); 

       int depth = queue.getCurrentDepth(); 
       System.out.println("Current depth: " + depth + "\n"); 
       if (depth == 0) { 
        return; 
       } 

       MQGetMessageOptions getOptions = new MQGetMessageOptions(); 
       getOptions.options = MQC.MQGMO_NO_WAIT + MQC.MQGMO_FAIL_IF_QUIESCING 
         + MQC.MQGMO_CONVERT; 
       while (true) { 
        MQMessage message = new MQMessage(); 
        try { 
         queue.get(message, getOptions); 
         byte[] b = new byte[message.getMessageLength()]; 
         message.readFully(b); 
         System.out.println(new String(b)); 
         message.clearMessage(); 
        } catch (IOException e) { 
         System.out.println("IOException during GET: " + e.getMessage()); 
         break; 
        } catch (MQException e) { 
         if (e.completionCode == 2 
           && e.reasonCode == MQException.MQRC_NO_MSG_AVAILABLE) { 
          if (depth > 0) { 
           System.out.println("All messages read."); 
          } 
         } else { 
          System.out.println("GET Exception: "+e); 
         } 
         break; 
        } 
       } 
       queue.close(); 
       _queueManager.disconnect(); 
      } 

      private void selectQMgr() throws MQException { 
       _queueManager = new MQQueueManager(qManager); 
      } 

      private void write() throws MQException { 
       int lineNum = 0; 
       int openOptions = MQC.MQOO_OUTPUT + MQC.MQOO_FAIL_IF_QUIESCING; 
       try { 
        MQQueue queue = _queueManager.accessQueue(outputQName, openOptions, 
          null, // default q manager 
          null, // no dynamic q name 
          null); // no alternate user id 

        DataInputStream input = new DataInputStream(System.in); 

        System.out.println("MQWrite v1.0 connected"); 
        System.out.println("and ready for input, terminate with ^Z\n\n"); 

        // Define a simple MQ message, and write some text in UTF format.. 
        MQMessage sendmsg = new MQMessage(); 
        sendmsg.format = MQC.MQFMT_STRING; 
        sendmsg.feedback = MQC.MQFB_NONE; 
        sendmsg.messageType = MQC.MQMT_DATAGRAM; 
        sendmsg.replyToQueueName = "ROGER.QUEUE"; 
        sendmsg.replyToQueueManagerName = qManager; 

        MQPutMessageOptions pmo = new MQPutMessageOptions(); // accept the 
                      // defaults, 
                      // same 
        // as MQPMO_DEFAULT constant 

        String line = "test message"; 
        sendmsg.clearMessage(); 
        sendmsg.messageId = MQC.MQMI_NONE; 
        sendmsg.correlationId = MQC.MQCI_NONE; 
        sendmsg.writeString(line); 

        // put the message on the queue 

        queue.put(sendmsg, pmo); 
        System.out.println(++lineNum + ": " + line); 

        queue.close(); 
        _queueManager.disconnect(); 

       } catch (com.ibm.mq.MQException mqex) { 
        System.out.println(mqex); 
       } catch (java.io.IOException ioex) { 
        System.out.println("An MQ IO error occurred : " + ioex); 
       } 

      } 
     } 

給出我得到下面的錯誤日誌 2016年9月24日14: 09:24 - 過程(1956.7)用戶(MUSR_MQADMIN)計劃(amqrmppa.exe) 主機(ABHI-PC)安裝(Installation1) VRMF(7.5.0.2)QMGR(QM_ORANGE)

AMQ9208:電子從主機Aneesh(192.168.0.7)收到反饋。

說明: 通過TCP/IP從Aneesh(192.168.0.7)接收數據時發生錯誤。此 可能是由於通信故障。 操作: 來自TCP/IP recv()調用的返回碼是10054(X'2746')。記錄這些值,並告訴系統管理員。

+0

你看一些建議[這裏](http://www-01.ibm.com/support/docview.wss?uid=swg21226703)? –

+0

我是否必須啓動任何**服務**以通過Java訪問MQ。如果是,那麼我該如何啓動服務。我已經使用** runmqsc **命令啓動了只有隊列管理器。 –

回答

2

您的應用程序在read方法中調用_queueManager.disconnect()。這會關閉與隊列管理器的連接。然後你的應用程序使用同一個斷開的_queueManager對象調用accessQueue方法。這會因連接錯誤而失敗。建議您從read刪除queueManager.disconnect()然後再嘗試。

UPDATE

夫婦的建議:

1)通過加入這一行MQEnvironment.properties.put(MQConstants.TRANSPORT_PROPERTY,CMQC.TRANSPORT_MQSERIES_CLIENT)

2)確保所述信道,QM_ORANGE.QM_APPLE您使用設置傳輸類型到客戶端是服務器連接(SVRCONN)類型通道。

這個問題可能會有所幫助:MQ queue manager closed channel immediately during connect

+0

評論'queueManager。斷開連接()'但沒有用仍然得到相同的異常 –

+0

告訴我們在哪一點你會得到異常? – Shashi

+0

我在通話過程中遇到異常 'readQ.selectQMgr(); ' '私人無效selectQMgr()拋出的MQException { _queueManager =新MQQueueManager(qManager); }' –