I am trying to put some messages from a JMS code to a local queue defined in local queue manager. I have defined a local Queue LQ
in WebSphere MQ and using JMS code to put messages. Am I doing it proper here. I am not seeing the messages in WebSphere queue.
Here is the code:
try {
MQQueueConnectionFactory cf = new MQQueueConnectionFactory();
//set up the Connection Configuration values
// Set the properties
cf.setStringProperty(WMQConstants.WMQ_HOST_NAME, "HostName");
cf.setIntProperty(WMQConstants.WMQ_PORT, 1414);
cf.setStringProperty(WMQConstants.WMQ_CHANNEL, "SYSTEM.DEF.SVRCONN");
cf.setIntProperty(WMQConstants.WMQ_CONNECTION_MODE, WMQConstants.WMQ_CM_CLIENT);
cf.setStringProperty(WMQConstants.WMQ_QUEUE_MANAGER, "TEST.JMS");
//JNDI is Not used Here
MQQueueConnection connection = (MQQueueConnection) cf.createQueueConnection();
MQQueueSession session = (MQQueueSession) connection.createQueueSession(true, Session.CLIENT_ACKNOWLEDGE);
MQQueue queue = (MQQueue) session.createQueue("queue:///LQ");
MQQueueSender sender = (MQQueueSender) session.createSender(queue);
MQQueueReceiver receiver = (MQQueueReceiver) session.createReceiver(queue);
long uniqueNumber = System.currentTimeMillis() % 1000;
JMSTextMessage message = (JMSTextMessage) session.createTextMessage("MQJMSTest "+ uniqueNumber);
//MQMessage message = (MQMessage) session.createTextMessage("MQJMSTest "+ uniqueNumber);
// Start the connection
connection.start();
sender.send(message);
System.out.println("Sent message:\\n" + message);
//JMSMessage receivedMessage = (JMSMessage) receiver.receive(10000);
// System.out.println("\\nReceived message:\\n" + receivedMessage);
sender.close();
receiver.close();
session.close();
connection.stop();
connection.close();
System.out.println("\\nSUCCESS\\n");
} catch (JMSException e) {
// TODO Auto-generated catch block
//e.printStackTrace();
System.out.println(e);
System.out.println("\\nFAILURE\\n");
}
catch (Exception e){
System.out.println(e);
System.out.println("\\nFAILURE\\n");
}