Thursday, November 10, 2005

Publishing Message to MQ Series

Nowdays service oriented architecture have become common,so there should be a quick way of publishing and receiving message from appserver to message oriented middleware like MQseries,a few lines of java code will make it.
// Get the MQQueueConnectionFactory
(requires com.ibm.mq.jar,com.ibm.mqjms.jar)
MQTopicConnectionFactory factory = new MQTopicConnectionFactory();
factory.setTransportType(JMSC.MQJMS_TP_CLIENT_MQ_TCPIP);//Transport Type

factory.setHostName(qmHost);//Host name
factory.setPort(portNum);//Port Number
factory.setQueueManager(qmName);//Queue Manager Name
connection = factory.createTopicConnection();//Start connection
connection.setClientID(clientID);//Set Client Id
//Got the connection start publishing message
connection.start();
session = connection.createTopicSession(true,
Session.AUTO_ACKNOWLEDGE);
TextMessage message = session.createTextMessage();
message.setText(Content); //Set the messsage content
TopicPublisher eventMQPublisher
eventMQPublisher = session.createPublisher(topic);
eventMQPublisher.publish(message);//Message Published



0 Comments:

Post a Comment

<< Home