2016-10-08 2 views
0

를 사용하여 MQ 서버의 큐 관리자에 연결할 수있다 -는 WebSphere MQ 오류가 발생했습니다 : 완성 코드 2 이유 코드 2058 . 나는 잘못된 큐 관리자 이름 때문에이 이유 코드를 알고 있습니다. 그러나 큐 관리자 이름은 정확합니다 ...가 어떻게 MQ 클라이언트</p> <p>오류가를 사용하여 MQ 서버에 메시지를 보내려고했다 MQ 클라이언트

WebSphere MQ 클라이언트를 설치 한 후 다음 명령을 실행했습니다. SET MQSERVER = QM_ORANGE/TCP/IPADDRESS (PORT NUMBER)

이 프로그램을 실행하십시오. public class MQSample {

// code identifier 
    static final String sccsid = "@(#) MQMBID sn=p750-002-131001_DE su=_FswqMCqGEeOZ3ui-rZDONA pn=MQJavaSamples/wmqjava/MQSample.java"; 

    // define the name of the QueueManager 
    private static final String qManager = "QM_ORANGE"; 
    // and define the name of the Queue 
    private static final String qName = "Q1"; 

    /** 
    * Main entry point 
    * 
    * @param args - command line arguments (ignored) 
    */ 
    public static void main(String args[]) { 
    try { 
     // Create a connection to the QueueManager 
     System.out.println("Connecting to queue manager: " + qManager); 
     MQQueueManager qMgr = new MQQueueManager(qManager); 

     // Set up the options on the queue we wish to open 
     //int openOptions = MQConstants.MQOO_INPUT_AS_Q_DEF | MQConstants.MQOO_OUTPUT; 
     int openOptions = MQConstants.MQOO_OUTPUT; 
    // int openOptions1 = MQConstants.MQOO_INPUT_AS_Q_DEF; 
     // Now specify the queue that we wish to open and the open options 
     System.out.println("Accessing queue: " + qName); 
     MQQueue queue = qMgr.accessQueue(qName, openOptions); 
     //MQQueue queue1 = qMgr.accessQueue(qName, openOptions1); 
     // Define a simple WebSphere MQ Message ... 
     MQMessage msg = new MQMessage(); 
     // ... and write some text in UTF8 format 
     msg.writeUTF("Hello, World!"); 

     // Specify the default put message options 
     MQPutMessageOptions pmo = new MQPutMessageOptions(); 

     // Put the message to the queue 
     System.out.println("Sending a message..."); 
     queue.put(msg, pmo); 


     // 



     openOptions = MQC.MQOO_INQUIRE + MQC.MQOO_FAIL_IF_QUIESCING 
       + MQC.MQOO_INPUT_SHARED; 

     queue = qMgr.accessQueue("QM_APPLE", 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(); 

     // Disconnect from the QueueManager 
     System.out.println("Disconnecting from the Queue Manager"); 
     qMgr.disconnect(); 
     System.out.println("Done!"); 
    } 
    catch (MQException ex) { 
     System.out.println("A WebSphere MQ Error occured : Completion Code " + ex.completionCode 
      + " Reason Code " + ex.reasonCode); 
     ex.printStackTrace(); 
     for (Throwable t = ex.getCause(); t != null; t = t.getCause()) { 
     System.out.println("... Caused by "); 
     t.printStackTrace(); 
     } 

    } 
    catch (java.io.IOException ex) { 
     System.out.println("An IOException occured whilst writing to the message buffer: " + ex); 
    } 
    return; 
    } 
} 

답변

4

MQSERVER 환경 변수를 설정했습니다. MQ C Client은이 환경 변수를 인식하고 이에 따라 IP 주소에 지정된 시스템에서 실행중인 큐 관리자에 연결합니다. MQ Java는 동일한 f}으로 작동하지 않습니다.

응용 프로그램에서 MQQueueManager 생성자에 큐 관리자 이름 만 지정했습니다. 이 평균 응용 프로그램은 서 v Y 인딩 연결을 통해 동일한 시스템에서 실행중인 큐 관리자에 연결하려고합니다.

다음과 같이 큐 관리자에 연결할 수 있습니다 (호스트, 포트, 채널 및 큐 관리자 이름 변경). 샘플은 MQ v8 Java 클라이언트로 작성되었습니다.

  Hashtable properties = new Hashtable<String, Object>(); 
      properties.put(MQConstants.HOST_NAME_PROPERTY, "qm.mycomp.com"); 
      properties.put(MQConstants.PORT_PROPERTY, 1414); 
      properties.put(MQConstants.CHANNEL_PROPERTY, "APP.SVRCONN"); 
      properties.put(MQConstants.USE_MQCSP_AUTHENTICATION_PROPERTY,"true"); 
      properties.put(MQConstants.USER_ID_PROPERTY, "myuserid"); 
      properties.put(MQConstants.PASSWORD_PROPERTY, "passw0rd"); 

      /** 
      * Connect to a queue manager 
      */ 
      MQQueueManager queueManager = new MQQueueManager("QM", properties); 

프로그램에서

그래서 당신은 하드 코드 연결 매개 변수에 원하지 않는 업데이트? MQSERVER 환경 변수를 사용하여 자체적으로 가져 와서 파싱하고 연결 매개 변수를 파싱 할 수 있습니다. 구성 파일 또는 LDAP 서버를 사용하여 연결 정보를 가져올 수도 있습니다.

당신은 전혀 MQ 설명서를 읽지 않은 II

업데이트. MQ 클라이언트는 여러 언어로 API를 제공하는 라이브러리/jars/.net 어셈블리 집합 등입니다. 이러한 API를 사용하여 큐 관리자와 통신하는 응용 프로그램을 개 _하십시오. 이것이 위의 프로그램에서 한 것입니다. 이 라이브러리가 없으면 큐 관리자에 연결할 수 없습니다 (많은 사람들은 큐 관리자를 서버로 생각합니다). 응용 프로그램이 큐 관리자와 동일한 시스템에서 실행될 때, 공유 메모리를 통해 큐 관리자와 통신 할 수 있습니다. 그러나 다른 기계에서 실행될 때 통신은 TCP/IP (또는 SNA)를 통해 이루어집니다.

호프가 혼란을 없애기를 바랍니다.

+0

예 sir ..이 동일한 기계에서 실행중인 큐 관리자 ...하지만 실제로 내 요구 사항은 코드를 IP 주소를 지정하지 않고 클라이언트 **를 통해 서버에서 실행중인 큐 관리자를 연결하는 것입니다 ** 어떤 명령을 사용하여 서버의 IP 주소를 설정할 수 있습니까 ?? –

+0

아니요 환경 변수를 사용하지 않고 ... 내 프로그램에서 언급 한 것처럼 큐 관리자 이름 만 전달합니다 .... 나는 TCP를 포함하고 있습니다 : TCP : Library1 = DLLName1 KeepAlive = 예 ClntSndBuffSize = ClntRcvBuffSize 32768 = 32768 Connect_Timeout = 0 CHANNELS : DefRecon = YES ServerConnectionParms = QM_ORANGE.QM_APPLE1/TCP/192.168.1.5 (1414)' –

+0

호스트 이름/IP 주소, 포트 및 채널이 없으면 응용 프로그램이 다른 시스템에서 실행중인 큐 관리자에 연결할 수 없습니다. – Shashi