Ejemplo n.º 1
0
 /** Setting up the connection */
 private void setupConnection() {
   if (log.isDebugEnabled()) {
     log.debug("Starting to setup the connection with the IBM MQ");
   }
   String hostname = properties.getProperty(IbmMqConstants.HOST_NAME);
   String channel = properties.getProperty(IbmMqConstants.CHANNEL);
   String qName = properties.getProperty(IbmMqConstants.MQ_QUEUE);
   String qManager = properties.getProperty(IbmMqConstants.MQ_QMGR);
   String port = properties.getProperty(IbmMqConstants.PORT);
   String userName = properties.getProperty(IbmMqConstants.USER_ID);
   String password = properties.getProperty(IbmMqConstants.PASSWORD);
   String sslEnabledS = properties.getProperty(IbmMqConstants.SSL_ENABLED);
   boolean sslEnabled = Boolean.parseBoolean(sslEnabledS);
   mqProperties.put(MQConstants.HOST_NAME_PROPERTY, hostname);
   mqProperties.put(MQConstants.PORT_PROPERTY, new Integer(port));
   mqProperties.put(MQConstants.CHANNEL_PROPERTY, channel);
   mqProperties.put(MQConstants.USER_ID_PROPERTY, userName);
   mqProperties.put(MQConstants.PASSWORD_PROPERTY, password);
   if (sslEnabled) {
     sslConnection();
   }
   /** Connect to a queue manager */
   try {
     queueManager = new MQQueueManager(qManager, mqProperties);
     int openOptions = MQConstants.MQOO_INPUT_AS_Q_DEF;
     queue = queueManager.accessQueue(qName, openOptions);
     log.info("IBM MQ " + qManager + " queue manager successfully connected");
     isConnected = true;
   } catch (MQException e) {
     handleException("Error while setup the IBM MQ connection", e);
     isConnected = false;
   }
 }
Ejemplo n.º 2
-1
  public static void main(String args[]) {
    try {
      MQEnvironment.hostname = "192.168.43.187";
      MQEnvironment.port = 1414;
      MQEnvironment.channel = "mymgrChannel";

      //            MQEnvironment.hostname = "10.10.10.93";
      //            MQEnvironment.port = 1415;
      //            MQEnvironment.channel = "ESBQManagerChannel";

      MQEnvironment.userID = "kirishanthy";
      MQEnvironment.password = "******";
      MQQueueManager qMgr = new MQQueueManager(qManager);
      int openOptions = MQConstants.MQOO_OUTPUT;
      MQQueue queue = qMgr.accessQueue(qName, openOptions);
      for (int i = 0; i < 1000; i++) {
        MQMessage msg = new MQMessage();
        //                String message = "this message from mymgr";
        String message = MQClientUtils.DEFAULT_PLACEORDER_PAYLOAD;
        msg.writeUTF(message);
        MQPutMessageOptions pmo = new MQPutMessageOptions();
        queue.put(msg, pmo);
      }
      queue.close();
      qMgr.disconnect();
    } catch (MQException ex) {
      ex.printStackTrace();
      System.out.println(
          "A WebSphere MQ Error occurred : Completion Code "
              + ex.completionCode
              + " Reason Code "
              + ex.reasonCode);

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