2016-05-04 7 views
2

現在、私はJAVA仮想ユーザプロトコルを使用してロードランナーでMQスクリプティングを行っています.1つの入力キューと1つの出力キューを使用しています。入力キューを使用してメッセージを正常に入力できますが、出力キューからメッセージを読み取ることができません。IBM MessageQueueまたはリモートMQからメッセージを読み取る方法

以下は、MQからPUT/GETメッセージに使用しているコードです。出力MQからメッセージを読む方法を教えてください。

lr.start_transaction("test_message"); 

try { 
     MQQueue destQueue1 = queueMgr.accessQueue(putQueueName, MQC.MQOO_INQUIRE); 
       pmo.options = MQC.MQPMO_NEW_MSG_ID; 
       requestMsg.replyToQueueName =getQueueName; 
       requestMsg.report=MQC.MQRO_PASS_MSG_ID; 
       requestMsg.format = MQC.MQFMT_STRING; 
       requestMsg.messageType=MQC.MQMT_REQUEST; 
       requestMsg.writeString(msgBody); 
       putQueue.put(requestMsg, pmo); 
      } catch(Exception e) { 
      lr.error_message("Error sending message."); 
      lr.exit(lr.EXIT_VUSER, lr.FAIL); 
      } 
      putQueue.close(); 

     // Get the response message object from the response queue 
     try { 
      responseMsg.correlationId = requestMsg.messageId; 
      gmo.matchOptions=MQC.MQMO_MATCH_CORREL_ID; 
      gmo.options= MQC.MQGMO_NO_SYNCPOINT; 
      gmo.matchOptions=MQC.MQMO_NONE; 
      gmo.options= MQC.MQGMO_SYNCPOINT; 
      gmo.options= MQC.MQGMO_CONVERT; 
      gmo.options= MQC.MQGMO_WAIT; 
      gmo.waitInterval=MQC.MQWI_UNLIMITED; 
      gmo.waitInterval=60000; 
      getQueue.get(responseMsg, gmo); 
      System.out.println("QueueDepth for get:"+getQueue.getCurrentDepth()); 
      //Check the message content 
    byte[] responseMsgData = responseMsg.readStringOfByteLength(responseMsg.getTotalMessageLength()).getBytes(); 
      String msg = new String(responseMsgData); 
      lr.output_message(msg); 
      } catch(Exception e) { 
      lr.error_message("Error receiving message."); 
      lr.exit(lr.EXIT_VUSER, lr.FAIL); 
      } 
     lr.end_transaction("test_message", lr.AUTO); 

答えて

1

MQには新しいようです。あなたのコードには複数の問題があります。 MQリクエスト/レスポンスのシナリオを示すコードを示します。コードはMQ v8を使用して開発されています。 MQのバージョンと必要に応じて変更してください。

/** 
* Reqeust reply scenario 
*/ 
public void mqRequestRespose() { 
     Hashtable<String, Object> properties; 

     try { 
      System.out.println("***Request/Reply Started *** "); 
      properties = new Hashtable<String, Object>(); 
      properties.put("hostname", "localhost"); 
      properties.put("port", new Integer(1414)); 
      properties.put("channel", "APP.SVRCONN.CHN"); 
      properties.put(MQConstants.USE_MQCSP_AUTHENTICATION_PROPERTY,"true"); 
      properties.put(MQConstants.USER_ID_PROPERTY, "username"); 
      properties.put(MQConstants.PASSWORD_PROPERTY, "password"); 

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

      /** 
      * Now create a subscription by providing our own temporary queue 
      */ 
      MQQueue mqRequestQ = queueManager.accessQueue("REQUEST.QUEUE", CMQC.MQOO_FAIL_IF_QUIESCING | CMQC.MQOO_OUTPUT); 
      MQQueue mqReplyQ = queueManager.accessQueue("REPLY.QUEUE", CMQC.MQOO_FAIL_IF_QUIESCING | CMQC.MQOO_INPUT_AS_Q_DEF); 

      /** 
      * Build a request message and send it to request queue. 
      */ 
      System.out.println("***Sending a request ***");     
      MQMessage msgRequest = new MQMessage(); 
      msgRequest.writeUTF("Give me quote for IBM"); 
      mqRequestQ.put(msgRequest); 

      /** 
      * Wait for 30 seconds to receive reply from reply queue 
      */ 
      System.out.println("*** Waiting for reply ***");     
      MQGetMessageOptions mqgmo = new MQGetMessageOptions(); 
      mqgmo.options = CMQC.MQGMO_WAIT | CMQC.MQGMO_CONVERT; 
      mqgmo.waitInterval = 30000; 
      mqgmo.matchOptions=CMQC.MQMO_MATCH_CORREL_ID; 

      MQMessage msgReply = new MQMessage(); 
      msgReply.correlationId = msgRequest.messageId; 
      try { 
       mqReplyQ.get(msgReply, mqgmo);     
       System.out.println("***Reply received***"); 
       System.out.println("STOCK QUOTE: USD" + msgReply.readUTF()); 
      }catch (MQException mqex) { 
       System.out.println("***No reply received in given time***");     
      } 
     } catch (Exception e) { 
      System.err.println(e); 
      e.printStackTrace(); 
      for (Throwable t = e.getCause(); t != null; t = t.getCause()) { 
       System.out.println("... Caused by "); 
       t.printStackTrace(); 
      } 
    }    
} 
+0

プロパティHashtableを作成しましたが、実際にはどこにも使用していません。 – ScrappyDev

+0

良い点。更新されたサンプルコード。 – Shashi

関連する問題