IBM MQ 使用出现问题
最近的项目中 要用到IBM MQ 。
写了四个接受类并实现了MessageListener监听,在servlet里面分别new 了四个类
在web 容器启动后 开始监听,但是出现的问题是 监听不到。
package com.founder.gome.bg.service.mq;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;public class MQServerlet extends HttpServlet {private static final long serialVersionUID = 1L;TntListener jt3 = null;SnListener jt4 = null;@Overridepublic void init() throws ServletException {jt3 = new TntListener();jt4 = new SnListener(); jt3.init(); jt4.init();@Overridepublic void destroy() {if(jt3!=null) {jt3.distory();}if(jt4!=null) {jt4.distory();}super.destroy();}}
import javax.jms.JMSException;import javax.jms.Message;import javax.jms.MessageListener;import javax.jms.Queue;import javax.jms.QueueConnection;import javax.jms.QueueReceiver;import javax.jms.QueueSession;import javax.jms.Session;import javax.jms.TextMessage;import com.ibm.mq.jms.MQQueueConnectionFactory;import com.ibm.msg.client.wmq.v6.jms.internal.JMSC;public class SnListener {SOService soService = (SOService) MQListener.wac.getBean("soService");private static QueueConnection connection = null;private static QueueSession session = null;Queue ioQueue;public void init(){try {MQQueueConnectionFactory factory = new MQQueueConnectionFactory();factory.setTransportType(JMSC.MQJMS_TP_CLIENT_MQ_TCPIP);factory.setQueueManager(MQCommon.getProperties().getProperty("MQ_MANAGER"));factory.setHostName(MQCommon.getProperties().getProperty("MQ_HOST_NAME"));factory.setChannel(MQCommon.getProperties().getProperty("MQ_CHANNEL"));factory.setPort(Integer.valueOf(MQCommon.getProperties().getProperty("MQ_PROT")));factory.setCCSID(Integer.valueOf(MQCommon.getProperties().getProperty("MQ_CCSID")));if(connection==null) {connection = factory.createQueueConnection(MQCommon.getProperties().getProperty("MQ_USER"), MQCommon.getProperties().getProperty("MQ_PWD"));connection.start();}if(session==null) {session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);;}ioQueue = session.createQueue("QL_GOME01_DRAGON_SN_TO_EC_SN");QueueReceiver queueReceiver = session.createReceiver(ioQueue);queueReceiver.setMessageListener(new MessageListener(){public void onMessage(Message message) {try {String messageTxt = ((TextMessage) message).getText();System.out.println("messageTxt is " + messageTxt);soService.getXML(messageTxt, "QL_GOME01_DRAGON_SN_TO_EC_SN");} catch (JMSException e) {e.printStackTrace();}}});} catch (JMSException e) {try {if(session !=null) {session.close();}if(connection!=null) {connection.close();}} catch (JMSException e1) {e1.printStackTrace();}e.printStackTrace();}} public void distory() { try {if(session != null) {session.close();session = null;}if(connection != null) {connection.close();connection = null;}} catch (JMSException e) {e.printStackTrace();} }}
package com.founder.gome.bg.service.mq;import javax.jms.JMSException;import javax.jms.Message;import javax.jms.MessageListener;import javax.jms.Queue;import javax.jms.QueueConnection;import javax.jms.QueueReceiver;import javax.jms.QueueSession;import javax.jms.Session;import javax.jms.TextMessage;import com.ibm.mq.jms.MQQueueConnectionFactory;import com.ibm.msg.client.wmq.v6.jms.internal.JMSC;public class TntListener {SOService soService = (SOService) MQListener.wac.getBean("soService");private static QueueConnection connection = null;private static QueueSession session = null;Queue ioQueue;public void init(){try {MQQueueConnectionFactory factory = new MQQueueConnectionFactory();factory.setTransportType(JMSC.MQJMS_TP_CLIENT_MQ_TCPIP);factory.setQueueManager(MQCommon.getProperties().getProperty("MQ_MANAGER"));factory.setHostName(MQCommon.getProperties().getProperty("MQ_HOST_NAME"));factory.setChannel(MQCommon.getProperties().getProperty("MQ_CHANNEL"));factory.setPort(Integer.valueOf(MQCommon.getProperties().getProperty("MQ_PROT")));factory.setCCSID(Integer.valueOf(MQCommon.getProperties().getProperty("MQ_CCSID")));if(connection==null) {connection = factory.createQueueConnection(MQCommon.getProperties().getProperty("MQ_USER"), MQCommon.getProperties().getProperty("MQ_PWD"));connection.start();}if(session==null) {session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);;}ioQueue = session.createQueue("QL_GOME01_DRAGON_TNT_TO_EC_TNT");QueueReceiver queueReceiver = session.createReceiver(ioQueue);queueReceiver.setMessageListener(new MessageListener(){public void onMessage(Message message) {try {String messageTxt = ((TextMessage) message).getText();System.out.println("messageTxt is " + messageTxt);soService.getXML(messageTxt, "QL_GOME01_DRAGON_TNT_TO_EC_TNT");} catch (JMSException e) {e.printStackTrace();}}});} catch (JMSException e) {try {if(session !=null) {session.close();}if(connection!=null) {connection.close();}} catch (JMSException e1) {e1.printStackTrace();}e.printStackTrace();}} public void distory() { try {if(session != null) {session.close();session = null;}if(connection != null) {connection.close();connection = null;}} catch (JMSException e) {e.printStackTrace();} }}
package com.founder.gome.bg.service.mq;import java.io.BufferedInputStream;import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.IOException;import java.io.InputStream;import java.util.Properties; public class MQCommon { public static Properties props = null; public static Properties getProperties() { try { props = new Properties(); InputStream in = new BufferedInputStream(new FileInputStream(MQListener.rootDir+File.separator+"WEB-INF"+File.separator+"classes"+File.separator+"MQ.properties")); props.load(in); in.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return props; } }