测试Jboss5与ActiveMQ5整合

0、安装JDK1.7

1、下载jboss-5.1.0.GA,解压jboss到D:\jboss-5.1.0.GA,bin/run来启动jboss,打开http://localhost:8080/web-console/测试是否安装成功

2、下载apache-activemq-5.7.0,解压activemq到D:\apache-activemq-5.7.0,bin\activemq.bat启动ActiveMQ,打开http://localhost:8161/admin/测试是否安装成功

3、下载ActiveMQ的rar资源组件包(老版本的ActiveMQ在ActiveMQ压缩包中就有,新版本的压缩包中没有需要单独下载),下载地址:

https://repository.cloudera.com/content/groups/cdh-build/org/apache/activemq/activemq-rar/5.7.0/

4、在D:\jboss-5.1.0.GA\server\default\deploy下面创建activemq-ra-5.7.0.rar目录,将activemq-rar-5.7.0.rar解压缩到这个目录下。

5、打开D:\jboss-5.1.0.GA\server\default\deploy\activemq-ra-5.7.0.rar\META-INF下的ra.xml文件,修改配置如下:

 

  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <!--  
  3.     Licensed to the Apache Software Foundation (ASF) under one or more  
  4.     contributor license agreements.  See the NOTICE file distributed with  
  5.     this work for additional information regarding copyright ownership.  
  6.     The ASF licenses this file to You under the Apache License, Version 2.0  
  7.     (the "License"); you may not use this file except in compliance with  
  8.     the License.  You may obtain a copy of the License at  
  9.      
  10.     http://www.apache.org/licenses/LICENSE-2.0  
  11.      
  12.     Unless required by applicable law or agreed to in writing, software  
  13.     distributed under the License is distributed on an "AS IS" BASIS,  
  14.     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  
  15.     See the License for the specific language governing permissions and  
  16.     limitations under the License.  
  17. -->  
  18.   
  19. <connector xmlns="http://java.sun.com/xml/ns/j2ee"  
  20.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  21.     xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee  
  22.     http://java.sun.com/xml/ns/j2ee/connector_1_5.xsd"  
  23.     version="1.5">  
  24.     <description>ActiveMQ  inbound and outbound JMS ResourceAdapter</description>  
  25.     <display-name>ActiveMQ JMS Resource Adapter</display-name>  
  26.     <vendor-name>activemq.org</vendor-name>  
  27.     <eis-type>JMS 1.1</eis-type>  
  28.     <resourceadapter-version>1.0</resourceadapter-version>  
  29.     <license>  
  30.         <description>  
  31.     Licensed to the Apache Software Foundation (ASF) under one or more  
  32.     contributor license agreements.  See the NOTICE file distributed with  
  33.     this work for additional information regarding copyright ownership.  
  34.     The ASF licenses this file to You under the Apache License, Version 2.0  
  35.     (the "License"); you may not use this file except in compliance with  
  36.     the License.  You may obtain a copy of the License at  
  37.      
  38.     http://www.apache.org/licenses/LICENSE-2.0  
  39.      
  40.     Unless required by applicable law or agreed to in writing, software  
  41.     distributed under the License is distributed on an "AS IS" BASIS,  
  42.     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  
  43.     See the License for the specific language governing permissions and  
  44.     limitations under the License.  
  45.         </description>  
  46.         <license-required>true</license-required>  
  47.     </license>  
  48.     <resourceadapter>  
  49.         <resourceadapter-class>org.apache.activemq.ra.ActiveMQResourceAdapter</resourceadapter-class>  
  50.         <config-property>  
  51.             <description>  
  52.               The URL to the ActiveMQ server that you want this connection to connect to.  If using  
  53.               an embedded broker, this value should be 'vm://localhost'.  
  54.             </description>  
  55.             <config-property-name>ServerUrl</config-property-name>  
  56.             <config-property-type>java.lang.String</config-property-type>  
  57.             <!--<config-property-value>tcp://localhost:61616</config-property-value>-->  
  58.             <config-property-value>vm://localhost</config-property-value>  
  59.         </config-property>  
  60.         <config-property>  
  61.             <description>The default user name that will be used to establish connections to the ActiveMQ server.</description>  
  62.             <config-property-name>UserName</config-property-name>  
  63.             <config-property-type>java.lang.String</config-property-type>  
  64.             <config-property-value>defaultUser</config-property-value>  
  65.         </config-property>  
  66.         <config-property>  
  67.             <description>The default password that will be used to log the default user into the ActiveMQ server.</description>  
  68.             <config-property-name>Password</config-property-name>  
  69.             <config-property-type>java.lang.String</config-property-type>  
  70.             <config-property-value>defaultPassword</config-property-value>  
  71.         </config-property>  
  72.         <config-property>  
  73.             <description>The client id that will be set on the connection that is established to the ActiveMQ server.</description>  
  74.             <config-property-name>Clientid</config-property-name>  
  75.             <config-property-type>java.lang.String</config-property-type>  
  76.         </config-property>  
  77.         <config-property>  
  78.             <description>Boolean to configure if outbound connections should reuse the inbound connection's session for sending messages.</description>  
  79.             <config-property-name>UseInboundSession</config-property-name>  
  80.             <config-property-type>java.lang.Boolean</config-property-type>  
  81.             <config-property-value>false</config-property-value>  
  82.         </config-property>  
  83.   
  84.               <!-- NOTE disable the following property if you do not wish to deploy an embedded broker -->  
  85.         <config-property>  
  86.             <description>  
  87.               Sets the XML configuration file used to configure the embedded ActiveMQ broker via   
  88.               Spring if using embedded mode.  
  89.                 
  90.               BrokerXmlConfig is the filename which is assumed to be on the classpath unless   
  91.               a URL is specified. So a value of foo/bar.xml would be assumed to be on the   
  92.               classpath whereas file:dir/file.xml would use the file system.   
  93.               Any valid URL string is supported.                
  94.             </description>  
  95.             <config-property-name>BrokerXmlConfig</config-property-name>  
  96.             <config-property-type>java.lang.String</config-property-type>  
  97.             <!--<config-property-value></config-property-value>-->  
  98.               
  99.                <config-property-value>xbean:broker-config.xml</config-property-value>  
  100.             <!--  
  101.              To use the broker-config.xml from the root for the RAR  
  102.              To use an external file or url location  
  103.                <config-property-value>xbean:file:///amq/config/jee/broker-config.xml</config-property-value>  
  104.             -->  
  105.         </config-property>  
  106.   
  107.         <outbound-resourceadapter>  
  108.             <connection-definition>  
  109.                 <managedconnectionfactory-class>org.apache.activemq.ra.ActiveMQManagedConnectionFactory</managedconnectionfactory-class>  
  110.                 <connectionfactory-interface>javax.jms.ConnectionFactory</connectionfactory-interface>  
  111.                 <connectionfactory-impl-class>org.apache.activemq.ra.ActiveMQConnectionFactory</connectionfactory-impl-class>  
  112.                 <connection-interface>javax.jms.Connection</connection-interface>  
  113.                 <connection-impl-class>org.apache.activemq.ra.ManagedConnectionProxy</connection-impl-class>  
  114.             </connection-definition>  
  115.             <connection-definition>  
  116.                 <managedconnectionfactory-class>org.apache.activemq.ra.ActiveMQManagedConnectionFactory</managedconnectionfactory-class>  
  117.                 <connectionfactory-interface>javax.jms.QueueConnectionFactory</connectionfactory-interface>  
  118.                 <connectionfactory-impl-class>org.apache.activemq.ra.ActiveMQConnectionFactory</connectionfactory-impl-class>  
  119.                 <connection-interface>javax.jms.QueueConnection</connection-interface>  
  120.                 <connection-impl-class>org.apache.activemq.ra.ManagedConnectionProxy</connection-impl-class>  
  121.             </connection-definition>  
  122.             <connection-definition>  
  123.                 <managedconnectionfactory-class>org.apache.activemq.ra.ActiveMQManagedConnectionFactory</managedconnectionfactory-class>  
  124.                 <connectionfactory-interface>javax.jms.TopicConnectionFactory</connectionfactory-interface>  
  125.                 <connectionfactory-impl-class>org.apache.activemq.ra.ActiveMQConnectionFactory</connectionfactory-impl-class>  
  126.                 <connection-interface>javax.jms.TopicConnection</connection-interface>  
  127.                 <connection-impl-class>org.apache.activemq.ra.ManagedConnectionProxy</connection-impl-class>  
  128.             </connection-definition>  
  129.             <transaction-support>XATransaction</transaction-support>  
  130.             <authentication-mechanism>  
  131.                 <authentication-mechanism-type>BasicPassword</authentication-mechanism-type>  
  132.                 <credential-interface>javax.resource.spi.security.PasswordCredential</credential-interface>  
  133.             </authentication-mechanism>  
  134.             <reauthentication-support>false</reauthentication-support>  
  135.         </outbound-resourceadapter>  
  136.         <inbound-resourceadapter>  
  137.             <messageadapter>  
  138.                 <messagelistener>  
  139.                     <messagelistener-type>javax.jms.MessageListener</messagelistener-type>  
  140.                     <activationspec>  
  141.                         <activationspec-class>org.apache.activemq.ra.ActiveMQActivationSpec</activationspec-class>  
  142.                           
  143.                         <required-config-property>  
  144.                             <config-property-name>destination</config-property-name>  
  145.                         </required-config-property>  
  146.                         <required-config-property>  
  147.                             <config-property-name>destinationType</config-property-name>  
  148.                         </required-config-property>  
  149.                           
  150.                     </activationspec>  
  151.                 </messagelistener>  
  152.             </messageadapter>  
  153.         </inbound-resourceadapter>  
  154.         <adminobject>  
  155.             <adminobject-interface>javax.jms.Queue</adminobject-interface>  
  156.             <adminobject-class>org.apache.activemq.command.ActiveMQQueue</adminobject-class>  
  157.             <config-property>  
  158.                 <config-property-name>PhysicalName</config-property-name>  
  159.                 <config-property-type>java.lang.String</config-property-type>  
  160.             </config-property>  
  161.         </adminobject>  
  162.         <adminobject>  
  163.             <adminobject-interface>javax.jms.Topic</adminobject-interface>  
  164.             <adminobject-class>org.apache.activemq.command.ActiveMQTopic</adminobject-class>  
  165.             <config-property>  
  166.                 <config-property-name>PhysicalName</config-property-name>  
  167.                 <config-property-type>java.lang.String</config-property-type>  
  168.             </config-property>  
  169.         </adminobject>  
  170.     </resourceadapter>  
  171. </connector>  

修改点:

   <!--<config-property-value>tcp://localhost:61616</config-property-value>-->             <config-property-value>vm://localhost</config-property-value>

  <!--<config-property-value></config-property-value>-->                             <config-property-value>xbean:broker-config.xml</config-property-value>    <!--              To use the broker-config.xml from the root for the RAR              To use an external file or url location                <config-property-value>xbean:file:///amq/config/jee/broker-config.xml</config-property-value>             -->

 

6、打开D:\jboss-5.1.0.GA\server\default\deploy\activemq-ra-5.7.0.rar\broker-config.xml文件,修改配置如下:

 

  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <!--  
  3.     Licensed to the Apache Software Foundation (ASF) under one or more  
  4.     contributor license agreements.  See the NOTICE file distributed with  
  5.     this work for additional information regarding copyright ownership.  
  6.     The ASF licenses this file to You under the Apache License, Version 2.0  
  7.     (the "License"); you may not use this file except in compliance with  
  8.     the License.  You may obtain a copy of the License at  
  9.      
  10.     http://www.apache.org/licenses/LICENSE-2.0  
  11.      
  12.     Unless required by applicable law or agreed to in writing, software  
  13.     distributed under the License is distributed on an "AS IS" BASIS,  
  14.     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  
  15.     See the License for the specific language governing permissions and  
  16.     limitations under the License.  
  17. -->  
  18. <!-- START SNIPPET: xbean -->  
  19. <beans  
  20.   xmlns="http://www.springframework.org/schema/beans"  
  21.   xmlns:amq="http://activemq.apache.org/schema/core"  
  22.   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  23.   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd  
  24.   http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">  
  25.   
  26.   <!--  shutdown hook is disabled as RAR classloader may be gone at shutdown -->  
  27.   <broker xmlns="http://activemq.apache.org/schema/core" useJmx="true" useShutdownHook="false" brokerName="bruce.broker1">  
  28.   
  29.      <managementContext>  
  30.        <!-- use appserver provided context instead of creating one,  
  31.             for jboss use: -Djboss.platform.mbeanserver -->  
  32.        <managementContext createConnector="false"/>  
  33.      </managementContext>  
  34.   
  35.     <persistenceAdapter>  
  36.        <kahaDB directory="activemq-data/kahadb"/>  
  37.        <!--<jdbcPersistenceAdapter dataSource="#oracle-ds"/>-->  
  38.      </persistenceAdapter>  
  39.   
  40.     <transportConnectors>  
  41.       <transportConnector name="bruce.broker1" uri="tcp://192.168.24.148:61616"/>  
  42.     </transportConnectors>  
  43.       
  44.   </broker>  
  45. </beans>  

修改点:

<broker xmlns="http://activemq.apache.org/schema/core" useJmx="true" useShutdownHook="false" brokerName="bruce.broker1">

   <transportConnectors>       <transportConnector name="bruce.broker1" uri="tcp://localhost:61616"/>     </transportConnectors>

 

7、配置jboss让activeMQ能跟随jboss启动。在D:\jboss-5.1.0.GA\server\default\deploy下新建activemq-ds.xml文件,添加内容如下:

 

  1. <?xml version="1.0" encoding="UTF-8"?>   
  2.   
  3. <!DOCTYPE connection-factories   
  4.     PUBLIC "-//JBoss//DTD JBOSS JCA Config 5.0//EN"   
  5.     "http://www.jboss.org/j2ee/dtd/jboss-ds_5_0.dtd">   
  6.   
  7. <connection-factories>   
  8.   
  9.    <tx-connection-factory>   
  10.       <jndi-name>activemq/QueueConnectionFactory</jndi-name>   
  11.       <xa-transaction/>   
  12.       <!--<use-java-context>false</use-java-context>-->    
  13.       <track-connection-by-tx/>   
  14.       <rar-name>activemq-ra-5.7.0.rar</rar-name>   
  15.       <connection-definition>javax.jms.QueueConnectionFactory</connection-definition>   
  16.       <ServerUrl>vm://localhost</ServerUrl>   
  17.       <!--   
  18.       <UserName>sa</UserName>   
  19.       <Password></Password>   
  20.       -->   
  21.       <min-pool-size>1</min-pool-size>   
  22.       <max-pool-size>200</max-pool-size>   
  23.       <blocking-timeout-millis>30000</blocking-timeout-millis>   
  24.       <idle-timeout-minutes>3</idle-timeout-minutes>   
  25.    </tx-connection-factory>   
  26.   
  27.    <tx-connection-factory>   
  28.       <jndi-name>activemq/TopicConnectionFactory</jndi-name>   
  29.       <xa-transaction/>   
  30.       <track-connection-by-tx/>   
  31.       <rar-name>activemq-ra-5.7.0.rar</rar-name>   
  32.       <connection-definition>javax.jms.TopicConnectionFactory</connection-definition>   
  33.       <ServerUrl>vm://localhost</ServerUrl>   
  34.       <!--   
  35.       <UserName>sa</UserName>   
  36.       <Password></Password>   
  37.       -->   
  38.       <min-pool-size>1</min-pool-size>   
  39.       <max-pool-size>200</max-pool-size>   
  40.       <blocking-timeout-millis>30000</blocking-timeout-millis>   
  41.       <idle-timeout-minutes>3</idle-timeout-minutes>   
  42.    </tx-connection-factory>   
  43.   
  44.    <mbean code="org.jboss.resource.deployment.AdminObject" name="activemq.queue:name=outboundQueue">   
  45.       <attribute name="JNDIName">activemq/queue/outbound</attribute>   
  46.       <depends optional-attribute-name="RARName">jboss.jca:service=RARDeployment,name='activemq-ra-5.7.0.rar'</depends>   
  47.       <attribute name="Type">javax.jms.Queue</attribute>   
  48.       <attribute name="Properties">PhysicalName=queue.outbound</attribute>   
  49.    </mbean>   
  50.   
  51.    <mbean code="org.jboss.resource.deployment.AdminObject" name="activemq.topic:name=inboundTopic">   
  52.       <attribute name="JNDIName">activemq/topic/inbound</attribute>   
  53.       <depends optional-attribute-name="RARName">jboss.jca:service=RARDeployment,name='activemq-ra-5.7.0.rar'</depends>   
  54.       <attribute name="Type">javax.jms.Topic</attribute>   
  55.       <attribute name="Properties">PhysicalName=topic.inbound</attribute>   
  56.    </mbean>   
  57.   
  58. </connection-factories>   

最后,启动jboss验证配置是否成功

查看控制台输出:

16:12:47,645 INFO  [BrokerService] Apache ActiveMQ 5.7.0 (bruce.broker1, ID:jialin-PC-58465-1370074367392-0:1) is starting 16:12:47,976 INFO  [TransportServerThreadSupport] Listening for connections at: tcp://127.0.0.1:61616 16:12:47,976 INFO  [TransportConnector] Connector bruce.broker1 Started 16:12:47,981 INFO  [BrokerService] Apache ActiveMQ 5.7.0 (bruce.broker1, ID:jialin-PC-58465-1370074367392-0:1) started

JNDI信息,可以看到队列和主题相关对象的绑定

16:12:48,560 INFO  [AdminObject] Bound admin object 'org.apache.activemq.command.ActiveMQQueue' at 'activemq/queue/outbound' 16:12:48,570 INFO  [AdminObject] Bound admin object 'org.apache.activemq.command.ActiveMQTopic' at 'activemq/topic/inbound' 16:12:48,741 INFO  [ConnectionFactoryBindingService] Bound ConnectionManager 'jboss.jca:service=ConnectionFactoryBinding,name=activemq/QueueConnectionFactory' to JNDI name 'activemq/QueueConnectionFactory' 16:12:48,795 INFO  [ConnectionFactoryBindingService] Bound ConnectionManager 'jboss.jca:service=ConnectionFactoryBinding,name=activemq/TopicConnectionFactory' to JNDI name 'java:activemq/TopicConnectionFactory'

 

成功!

 

posted @ 2013-10-15 18:12  huidaoli  阅读(315)  评论(0编辑  收藏  举报