jboss EAP 6.2 + Message Drive Bean(MDB) 整合IBM Webshpere MQ 7.5

上一篇我们知道了消息驱动Bean的基本用法,实际大型分布式企业应用中,往往会采用高性能的商业Queue产品,比如IBM Webshpere MQ(目前最新版本是7.5 ),下面讲解下如何在Jboss EAP 6.2 版本上整合Webshpere MQ 7.5

 

一、修改jboss的standalone-full.xml

a) 添加IBM的resource-adapters

找到<subsystem xmlns="urn:jboss:domain:resource-adapters:1.1"/> 改成下面这样(注:里面的参数值,大家根据实际情况,自行修改)

jboss EAP 6.2 + Message Drive Bean(MDB)  整合IBM Webshpere MQ 
7.5
 1         <subsystem xmlns="urn:jboss:domain:resource-adapters:1.1">
 2             <resource-adapters>
 3                 <resource-adapter id="wmq.jmsra.rar">
 4                     <archive>
 5                         wmq.jmsra.rar
 6                     </archive>
 7                     <transaction-support>NoTransaction</transaction-support>
 8                     <connection-definitions>
 9                         <connection-definition class-name="com.ibm.mq.connector.outbound.ManagedConnectionFactoryImpl" jndi-name="java:/MyConnectionFactoryCnblogs" use-java-context="true" pool-name="connectionfactorypoolcnblogs">
10                             <config-property name="port">
11                                 1414
12                             </config-property>
13                             <config-property name="hostName">
14                                 172.21.126.177
15                             </config-property>
16                             <config-property name="channel">
17                                 DC.SVRCONN
18                             </config-property>
19                             <config-property name="transportType">
20                                 CLIENT
21                             </config-property>
22                             <config-property name="queueManager">
23                                 QM_APPLE
24                             </config-property>
25                         </connection-definition>
26                     </connection-definitions>
27                     <admin-objects>
28                         <admin-object class-name="com.ibm.mq.connector.outbound.MQQueueProxy" jndi-name="java:/queue/Q1" use-java-context="true" pool-name="Q1pool">
29                             <config-property name="baseQueueName">
30                                 Q1
31                             </config-property>
32                             <config-property name="targetClient">
33                                 MQ
34                             </config-property>
35                             <config-property name="baseQueueManagerName">
36                                 QM_APPLE
37                             </config-property>
38                         </admin-object>
39                     </admin-objects>
40                 </resource-adapter>
41             </resource-adapters>
42         </subsystem>
jboss EAP 6.2 + Message Drive Bean(MDB)  整合IBM Webshpere MQ 
7.5

 

 b) 找到<subsystem xmlns="urn:jboss:domain:ejb3:1.4">下的<mdb>节点,改成

jboss EAP 6.2 + Message Drive Bean(MDB)  整合IBM Webshpere MQ 
7.5
1             <mdb>
2                 <resource-adapter-ref resource-adapter-name="wmq.jmsra.rar"/>
3                 <bean-instance-pool-ref pool-name="mdb-strict-max-pool"/>
4             </mdb>
jboss EAP 6.2 + Message Drive Bean(MDB)  整合IBM Webshpere MQ 
7.5

 

二、部署wmq.jmsra.rar

IBM MQ的安装目录 C:\Program Files (x86)\IBM\WebSphere MQ\java\lib\jca 下有一个wmq.jmsra.rar文件,把它复制到

%JBOSS_HOME%\standalone\deployments 下,jboss启动后,将自动部署该rar

注:rar包的版本必须与MQ相符(即:如果你要监听MQ 7.5的队列消息,则该rar必须是MQ 7.5自带的)

附: 7.5版wmq.jmsra.rar的下载地址 http://pan.baidu.com/s/1jG5bWAM

 

三、MDB端的配置
a) 注解方式

jboss EAP 6.2 + Message Drive Bean(MDB)  整合IBM Webshpere MQ 
7.5
 1 import javax.ejb.ActivationConfigProperty;
 2 import javax.ejb.MessageDriven;
 3 import javax.jms.JMSException;
 4 import javax.jms.Message;
 5 import javax.jms.MessageListener;
 6 import javax.jms.TextMessage;
 7 import util.LoggerUtil;
 8 
 9 @MessageDriven(name = "WebSphereMQMDB", activationConfig = {
10         @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
11         @ActivationConfigProperty(propertyName = "useJNDI", propertyValue = "false"),
12         @ActivationConfigProperty(propertyName = "hostName", propertyValue = "172.21.126.177"),
13         @ActivationConfigProperty(propertyName = "port", propertyValue = "1414"),
14         @ActivationConfigProperty(propertyName = "channel", propertyValue = "DC.SVRCONN"),
15         @ActivationConfigProperty(propertyName = "queueManager", propertyValue = "QM_APPLE"),
16         @ActivationConfigProperty(propertyName = "destination", propertyValue = "Q1"),
17         @ActivationConfigProperty(propertyName = "transportType", propertyValue = "CLIENT") })
18 public class HelloWorldMDB implements MessageListener {
jboss EAP 6.2 + Message Drive Bean(MDB)  整合IBM Webshpere MQ 
7.5

注:HelloWorldMDB的onMessage方法处理跟上一篇完全相同,就不重复了。

 

b) jboss-ejb3.xml 方式

jboss EAP 6.2 + Message Drive Bean(MDB)  整合IBM Webshpere MQ 
7.5
 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <jboss:ejb-jar xmlns:jboss="http://www.jboss.com/xml/ns/javaee"
 3     xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4     xmlns:c="urn:clustering:1.0"
 5     xmlns:r="urn:resource-adapter-binding"
 6     xsi:schemaLocation="http://www.jboss.com/xml/ns/javaee http://www.jboss.org/j2ee/schema/jboss-ejb3-2_0.xsd http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd"
 7     version="3.1" impl-version="2.0">
 8     <enterprise-beans>
 9         <message-driven>
10             <ejb-name>WebSphereMQMDB</ejb-name>
11             <ejb-class>mdb.HelloWorldMDB</ejb-class>
12             <activation-config>                
13                 <activation-config-property>
14                     <activation-config-property-name>destinationType</activation-config-property-name>
15                     <activation-config-property-value>javax.jms.Queue</activation-config-property-value>
16                 </activation-config-property>
17                 <activation-config-property>
18                     <activation-config-property-name>useJNDI</activation-config-property-name>
19                     <activation-config-property-value>false</activation-config-property-value>
20                 </activation-config-property>
21                 <activation-config-property>
22                     <activation-config-property-name>hostName</activation-config-property-name>
23                     <activation-config-property-value>172.21.126.177</activation-config-property-value>
24                 </activation-config-property>
25                 <activation-config-property>
26                     <activation-config-property-name>port</activation-config-property-name>
27                     <activation-config-property-value>1414</activation-config-property-value>
28                 </activation-config-property>
29                 <activation-config-property>
30                     <activation-config-property-name>channel</activation-config-property-name>
31                     <activation-config-property-value>DC.SVRCONN</activation-config-property-value>
32                 </activation-config-property>
33                 <activation-config-property>
34                     <activation-config-property-name>queueManager</activation-config-property-name>
35                     <activation-config-property-value>QM_APPLE</activation-config-property-value>
36                 </activation-config-property>
37                 <activation-config-property>
38                     <activation-config-property-name>destination</activation-config-property-name>
39                     <activation-config-property-value>Q1</activation-config-property-value>
40                 </activation-config-property>
41                 <activation-config-property>
42                     <activation-config-property-name>transportType</activation-config-property-name>
43                     <activation-config-property-value>CLIENT</activation-config-property-value>
44                 </activation-config-property>
45             </activation-config>
46         </message-driven>
47     </enterprise-beans>    
48 </jboss:ejb-jar>
jboss EAP 6.2 + Message Drive Bean(MDB)  整合IBM Webshpere MQ 
7.5

这二种配置方式完全等效

 

四、测试验证

a) 以standalone-full.xml 配置启动jboss

%jboss_home%\standalone\configuration>move standalone.xml standalone_backup.xml

%jboss_home%\standalone\configuration>copy standalone-full.xml standalone.xml

%jboss_home%\standalone\configuration>..\..\bin\standalone.bat

 

b) 在MQ所在服务器上,用WebShpere MQ资源管理器,向Q1放入一条测试消息

jboss EAP 6.2 + Message Drive Bean(MDB)  整合IBM Webshpere MQ 
7.5 

顺利的话,Jboss控制台上,会马上显示已收到消息

jboss EAP 6.2 + Message Drive Bean(MDB)  整合IBM Webshpere MQ 
7.5

同时在%JBOSS_HOME%\standalone\log\server.log日志里,也能找到相关记录

12:11:12,559 INFO  [class util.LoggerUtil] (default-threads - 2) Received Message from queue: TEST MESSAGE
12:11:12,560 INFO  [stdout] (default-threads - 2) Received Message from queue: TEST MESSAGE

jboss EAP 6.2 + Message Drive Bean(MDB) 整合IBM Webshpere MQ 7.5

上一篇:微軟将从 .NET 4 以后的版本弃用 System.Data.OracleClient 以及Oracle 的各种连接方法


下一篇:Coursera台大机器学习技法课程笔记10-Random forest