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); } }
/** Receiving message from queue */ private void messageFromQueue() { try { MQMessage rcvMessage = new MQMessage(); MQGetMessageOptions gmo = new MQGetMessageOptions(); queue.get(rcvMessage, gmo); String msgText = rcvMessage.readUTF(); injectIbmMqMessage(msgText); } catch (MQException e) { int reason = e.reasonCode; if (MQConstants.MQRC_CONNECTION_BROKEN == reason) { isConnected = false; log.error("IBM MQ Connection Broken"); } else if (MQConstants.MQRC_NO_MSG_AVAILABLE != reason) { log.error("Error while getting messages from queue", e); } } catch (IOException e) { handleException("", e); } }