文章出處

上一篇我們知道了消息驅動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"/> 改成下面這樣(注:里面的參數值,大家根據實際情況,自行修改)

 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="channel">
14                         DC.SVRCONN
15                     </config-property>
16                     <config-property name="hostName">
17                         localhost
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         </resource-adapter>
28     </resource-adapters>
29 </subsystem>

 

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

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>

 

二、部署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) 注解方式

 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 {

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

 

b) jboss-ejb3.xml 方式

 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>

這二種配置方式完全等效

 

四、測試驗證

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控制臺上,會馬上顯示已收到消息

同時在%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

 


文章列表




Avast logo

Avast 防毒軟體已檢查此封電子郵件的病毒。
www.avast.com


arrow
arrow
    全站熱搜
    創作者介紹
    創作者 大師兄 的頭像
    大師兄

    IT工程師數位筆記本

    大師兄 發表在 痞客邦 留言(0) 人氣()