最近的项目中 要用到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;
@Override
public void init() throws ServletException {
jt3 = new TntListener();
jt4 = new SnListener();
jt3.init();
jt4.init();
@Override
public 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;
}
}
分享到:
相关推荐
IBM MQ使用方法 IBM MQ使用方法 IBM MQ使用方法
A IBM MQ client is part of the product that can be installed on its own, on a separate machine from the base product and server. You can run an IBM MQ application on an IBM MQ client and it can ...
下载后解压即可使用,专门测试远程和本地IBMMQ数据,可以导入导出数据
jmeter插件,用于进行IBM MQ测试。 部署插件之后,可进行简单配置,即可发送消息到mq通道中 使用方法参见 https://testerhome.com/notes/2193
MQ频繁出现的错误代码请查看excel文档,如果没有请查看另外一份文档, 有英文和中文。基本上覆盖了MQ所有的问题码。MQ错误码大全,希望对您有所帮助(错误码已排序,方便大家查找,使用)。
Java连接IBM WebSphere MQ 7处理队列信息所需jar包,从安装目录直接打的包。主要包括: /com.ibm.mq.commonservices.jar /com.ibm.mq.defaultconfig.jar /com.ibm.mq.fta.jar /com.ibm.mq.headers.jar /...
JAVA连接IBM MQ,具体的详细说明,请再csdn上面搜索JAVA连接IBM MQ关键词
IBM MQ 使用指南,MQ快速入门,欢迎下载使用!
ibmmq所需jar包,用于ibmmq连接建立,消息发送与接收,导入这些jar就能完成ibmmq相关功能。
IBM MQ群集基本概念、群集基本使用、配置、实例,简单的使用技巧
JAVA IBM MQ 接收消息、发送消息例子
IBM MQ 7.5.0 windows版本全部仅需要一次下载即可使用
ibm mq开发教程.pdf
一个简单的IBM MQ操作例子,put方法和get方法
IBM MQ经常被一些政府公共部门,银行等企业用来做数据传输和报文收发,在互联网应用的开发中较少见到,资源为MQjava 代码
IBM_MQ_使用指南
Spring 集成 IBM MQ 监听配置,包括用户管理配置和一些基础配置信息
IBM MQ将消息发送至远程队列,文档详细,有截图,有命令
IBM WebSphere MQ是IBM业界领先面向消息的中间件产品,也是MQ系列产品的基础和核心,它使不同的应用程序能够以企业级的性能,在广泛的平台上安全而可靠地通讯。