可以在tomcat中读取 rabbitmq 消息ibm mq消息吗

& 请教高手,tomcat和activeMQ 集成,越详细越好
网上的资料都没让我搞明白,现在已经没耐心搞下去了,请教高手
两种方法,
1。activemq有一个机遇tomcat的web console,可以在这个web console中嵌入你的工程。
2。在你的web项目中嵌入activemq的引用,配置jndi描述符指向activemq,你的应用通过jndi引用activemq的工厂收发消息。
Create the file &webapp-root&/META-INF/context.xml. Here is an example:
&Context antiJARLocking="true"&
name="jms/ConnectionFactory"
auth="Container"
type="org.apache.activemq.ActiveMQConnectionFactory"
description="JMS Connection Factory"
factory="org.apache.activemq.jndi.JNDIReferenceFactory"
brokerURL="tcp://localhost:61616"
brokerName="LocalActiveMQBroker"
useEmbeddedBroker="false"/&
&Resource name="jms/topic/MyTopic
auth="Container"
type="org.mand.ActiveMQTopic"
factory="org.apache.activemq.jndi.JNDIReferenceFactory"
physicalName="MY.TEST.FOO"/&
&Resource name="jms/queue/MyQueue"
auth="Container"
type="org.mand.ActiveMQQueue"
factory="org.apache.activemq.jndi.JNDIReferenceFactory"
physicalName="MY.TEST.FOO.QUEUE"/&
&/Context&
This will setup the JNDI for the ConectionFactory and Topic to work within Tomcat.
Here is some example code that will publish a test message to the MY.TEST.FOO Topic:
InitialContext initCtx = new InitialContext();
Context envContext = (Context) initCtx.lookup("java:comp/env");
ConnectionFactory connectionFactory = (ConnectionFactory) envContext.lookup("jms/ConnectionFactory");
Connection connection = connectionFactory.createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = session.createProducer((Destination) envContext.lookup("jms/topic/MyTopic"));
Message testMessage = session.createMessage();
testMessage.setStringProperty("testKey", "testValue");
producer.send(testMessage);
} catch (NamingException e) {
// TODO handle exception
} catch (JMSException e) {
// TODO handle exception
上面的代码来自
已解决问题
未解决问题在Tomcat 6.0下用JNDI连接IBM MQ 6.0的配置方法 - 推酷
在Tomcat 6.0下用JNDI连接IBM MQ 6.0的配置方法
假设在IBM MQ中定义的队列管理器的名为QueueManager, 端口1414,CCSID 437 ,创建名为LQ1,LQ2的队列分别用于发送和接收消息, 服务器连接通道名为SVRCONN。
1.项目包依赖
确保在项目的Classpath中导入了以下的jar包:
com.ibm.mq.jar ( %WebSphere MQ Root% /Java/lib/ )
com.ibm.mqjms.jar ( %WebSphere MQ Root% /Java/lib/ )
connector.jar ( %WebSphere MQ Root% /Java/lib/ )
dhbcore.jar ( %WebSphere MQ Root% /Java/lib/ )
geronimo-j2ee-management_1.0_spec-1.0.jar
geronimo-jms_1.1_spec-1.0.jar
如果需使用spring的JmsTemplate方式来读写MQ,还需要导入
spring.jar和commons-logging.jar
2.Tomcat的配置
在Tomcat的安装目录下,找到conf子目录下的context.xml, 默认情况下该文件的内容为:
&!-- The contents of this file will be loaded for each web application --&
&!-- Default set of monitored resources --&
&WatchedResource&WEB-INF/web.xml&/WatchedResource&
&!-- Uncomment this to disable session persistence across Tomcat restarts --&
&Manager pathname=&& /&
&/Context&
将其修改为:
&!-- The contents of this file will be loaded for each web application --&
&!-- Default set of monitored resources --&
&WatchedResource&WEB-INF/web.xml&/WatchedResource&
&!-- Uncomment this to disable session persistence across Tomcat restarts --&
&Manager pathname=&& /&
&!—连接工厂定义--&
name=&jms/queueConnectionFactory&
auth=&Container&
type=&com.ibm.mq.jms.MQConnectionFactory&
factory=&com.ibm.mq.jms.MQConnectionFactoryFactory&
description=&JMS Queue Connection Factory for sending messages&
HOST=&127.0.0.1&
PORT=&1414&
CHAN=&SVRCONN&
CCSID=&437&
QMGR=&QueueManager&
&!—队列定义--&
name=&jms/sendMsgQueue&
auth=&Container&
type=&com.ibm.mq.jms.MQQueue&
factory=&com.ibm.mq.jms.MQQueueFactory&
description=&JMS Queue for sending messages to app&
CCSID=&437&
name=&jms/recvMsgQueue&
auth=&Container&
type=&com.ibm.mq.jms.MQQueue&
factory=&com.ibm.mq.jms.MQQueueFactory&
description=&JMS Queue for receiving messages from app&
CCSID=&437&
&/Context&
也就是在Context元素下新增Resource子元素。
在Resource元素中,根据具体环境不同需要修改的属性有:
Name : JNDI的名称
HOST: 主机名
PORT: 队列管理器的端口号
CHAN:服务器通道名
CCSID:编码字符集标识
QMGR:队列管理器名
QU: 队列名
3.应用程序的配置
在web.xml中加入以下内容:
&!—连接工厂的JNDI引用--&
&resource-env-ref&
&resource-env-ref-name& jms/queueConnectionFactory&/resource-env-ref-name&
&resource-env-ref-type& javax.jms.QueueConnectionFactory&/resource-env-ref-type&
&/resource-env-ref&
&!—队列的JNDI引用--&
&resource-env-ref&
&resource-env-ref-name&jms/sendMsgQueue&/resource-env-ref-name&
&resource-env-ref-type&javax.jms.Queue&/resource-env-ref-type&
&/resource-env-ref&
&resource-env-ref&
&resource-env-ref-name&jms/recvMsgQueue&/resource-env-ref-name&
&resource-env-ref-type&javax.jms.Queue&/resource-env-ref-type&
&/resource-env-ref&
测试程序如使用spring JmsTemplate方式操作MQ,在spring配置文件中JMS资源定义部分为:
&!-- 连接工厂定义 --&
&bean id=&jmsConnectionFactory& class=&org.springframework.jndi.JndiObjectFactoryBean&&
&property name=&jndiName&&
&value&java:comp/env/jms/queueConnectionFactory&/value&
&/property&
&!-- 队列定义 --&
&bean id=&sendQueue& class=&org.springframework.jndi.JndiObjectFactoryBean&&
&property name=&jndiName& value=&java:comp/env/jms/sendMsgQueue& /&
&bean id=&recvQueue& class=&org.springframework.jndi.JndiObjectFactoryBean&&
&property name=&jndiName& value=&java:comp/env/jms/recvMsgQueue& /&
4. MQ编码字符集的修改
在中文系统下IBM MQ默认的编码字符集标识(CCSID)为1381,也就是简体中文编码。但是如果CCSID用1381的话,在Tomcat连接队列管理器时会出现错误,错误的Reason Code 为CCSID不能识别(至于为什么1381不能识别还不清楚),所以要修改CCSID。经过验证,CCSID=437 (西欧字符编码)可以连上队列管理器(貌似只要不是1381都能连,faint)。当然,IBM MQ里队列管理器的CCSID应修改为对应CCSID,方法如下:
假如队列管理器名为QueueManager,
(1) 启动QueueManager
(2) 在Dos命令行窗口下:
/& runmqsc QueueManager (回车)
ALTER QMGR FORCE CCSID(437)
End (退出)
(3) 重启QueueManager
如果一切正常,QueueManager的CCSID会修改为437
已发表评论数()
已收藏到推刊!
请填写推刊名
描述不能大于100个字符!
权限设置: 公开
仅自己可见
正文不准确
排版有问题
没有分页内容
视频无法显示
图片无法显示在Tomcat&6.0下用JNDI连接IBM&MQ&6.0的配置方法(一)
& 在tomcat6.0下用JMS连接MQ队列,整理方法如下:
假设在MQ中定义的队列管理器的名为QueueManager, 端口1414, CCSID 437
,队列名为userMsgQueue, gwMsgQueue, 服务器通道名为FA。
1.确保在项目的Classpath中导入了以下的jar包:
com.ibm.mq.jar&&&&
( %WebSphere MQ Root% \Java\lib\ )
com.ibm.mqjms.jar& ( %WebSphere MQ Root%
\Java\lib\ )
connector.jar&&&&&&&
( %WebSphere MQ Root% \Java\lib\ )
dhbcore.jar&&&&&&&&
( %WebSphere MQ Root% \Java\lib\ )
geronimo-j2ee-management_1.0_spec-1.0.jar
geronimo-jms_1.1_spec-1.0.jar
本文的测试程序使用spring的JmsTemplate方式来操作MQ,所以还需要导入
spring.jar和commons-logging.jar
2.Tomcat的配置
在Tomcat的安装目录下,找到conf子目录下的context.xml, 默认情况下该文件的内容为:
&!-- The contents of this file will be loaded for
each web application --&
&!-- Default set of monitored resources
&WatchedResource&WEB-INF/web.xml&/WatchedResource&
&!-- Uncomment this to disable session persistence
across Tomcat restarts --&
&Manager pathname="" /&
&/Context&
将其修改为:
&!-- The contents of this file will be loaded for
each web application --&
&!-- Default set of monitored resources
&WatchedResource&WEB-INF/web.xml&/WatchedResource&
&!-- Uncomment this to disable session persistence
across Tomcat restarts --&
&Manager pathname="" /&
&!—连接工厂定义--&
& &Resource
name="jms/queueConnectionFactory"
auth="Container"
type="com.ibm.mq.jms.MQConnectionFactory"
factory="com.ibm.mq.jms.MQConnectionFactoryFactory"
description="JMS Queue Connection Factory for sending messages"
HOST="127.0.0.1"
PORT="1414"
CCSID="437"
QMGR="QueueManager"
&!—队列定义--&
name="jms/gwMsgQueue"
auth="Container"
type="com.ibm.mq.jms.MQQueue"
factory="com.ibm.mq.jms.MQQueueFactory"
description="JMS Queue for receiving messages from Dialog"
QU="gwMsgQueue"
CCSID="437"
name="jms/userMsgQueue"
auth="Container"
type="com.ibm.mq.jms.MQQueue"
factory="com.ibm.mq.jms.MQQueueFactory"
description="JMS Queue for receiving messages from Dialog"
QU="userMsgQueue"
CCSID="437"
&/Context&
也就是在Context元素下新增Resource子元素。
在Resource元素中,根据具体环境不同需要修改的属性有:
Name : JNDI的名称
HOST: 主机名
PORT: 队列管理器的端口号
CHAN:服务器通道名
CCSID:编码字符集标识
QMGR:队列管理器名
QU:&& 队列名
已投稿到:
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。

我要回帖

更多关于 jms ibm mq接收消息 的文章

 

随机推荐