`

JBOSS5+ActiveMQ5.7集成

阅读更多
 

JBOSS5+ActiveMQ5.7集成

分类: J2EE 框架/工具 175人阅读 评论(2) 收藏 举报

最近项目中需要集成消息中间件来处理消息,选择了ActiveMQ这款中间件的开源产品。由于项目用的应用服务器为JBOSS,所以自然就想到如何把两者结合使用。

 

在ActiveMQ官方网站中给出了答案,网站中用到的是

ActiveMQ4.0.1+JBOSS4.0.4+JDK1.5+ANT1.6.2,我们项目中用的是

jboss-5.1.0.GA+JDK1.7+ActiveMQ5.7.0另外用ANT1.8.4做的集成测试。

 

ActiveMQ和JBOSS集成地址:http://activemq.apache.org/integrating-apache-activemq-with-jboss.html

 

具体做法:

1.        安装JDK(不说了,too easy)

2.        安装JBOSS(解压就好)

3.        下载ActiveMQ的rar资源组件包【老版本的ActiveMQ在ActiveMQ压缩包中就有,新版本的压缩包中没有需要单独下载】(如何对J2EE的容器组件开发模型了解的都清楚,j2ee中有五个组件,其中有一个就是资源组件,我们要下载的ActiveMQ的rar文件就是一个资源组件):

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

 

4.        解压RAR拷贝到JBOSS的default/deploy中

5.        配置 activemq(1):修改 META-INF/ra.xml

 

  1. <?xmlversionxmlversion="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 informationregarding copyright ownership.  
  6.     The ASF licenses this file to You under theApache License, Version 2.0  
  7.     (the "License"); you may not usethis 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 agreedto in writing, software  
  13.     distributed under the License isdistributed on an "AS IS" BASIS,  
  14.     WITHOUT WARRANTIES OR CONDITIONS OF ANYKIND, either express or implied.  
  15.     See the License for the specific languagegoverning permissions and  
  16.     limitations under the License.  
  17. -->  
  18.    
  19. <connectorxmlnsconnectorxmlns="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 JMSResourceAdapter</description>  
  25.     <display-name>ActiveMQ JMS ResourceAdapter</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 informationregarding copyright ownership.  
  34.     The ASF licenses this file to You under theApache License, Version 2.0  
  35.     (the "License"); you may not usethis 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 agreedto in writing, software  
  41.     distributed under the License isdistributed on an "AS IS" BASIS,  
  42.     WITHOUT WARRANTIES OR CONDITIONS OF ANYKIND, either express or implied.  
  43.     See the License for the specific languagegoverning 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 serverthat you want this connection to connect to. If using  
  53.               an embedded broker, this valueshould 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 username that will be used to establish connections to the ActiveMQserver.</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 defaultpassword that will be used to log the default user into the ActiveMQserver.</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 idthat will be set on the connection that is established to the ActiveMQserver.</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 configureif outbound connections should reuse the inbound connection's session forsending 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 propertyif you do not wish to deploy an embedded broker -->  
  85.         <config-property>  
  86.             <description>  
  87.               Sets the XML configuration file used toconfigure the embedded ActiveMQ broker via  
  88.               Spring if using embedded mode.  
  89.                
  90.               BrokerXmlConfig is the filenamewhich is assumed to be on the classpath unless  
  91.               a URL is specified. So a value offoo/bar.xml would be assumed to be on the  
  92.               classpath whereasfile:dir/file.xml would use the file system.  
  93.               Any valid URL string issupported.               
  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 fromthe root for the RAR  
  102.              To use an external file or urllocation  
  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>  


 

 

6.        配置 activemq (2):修改 broker-config.xml 文件

 

  1. <?xmlversionxmlversion="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 informationregarding copyright ownership.  
  6.     The ASF licenses this file to You under theApache License, Version 2.0  
  7.     (the "License"); you may not usethis 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 agreedto in writing, software  
  13.     distributed under the License isdistributed on an "AS IS" BASIS,  
  14.     WITHOUT WARRANTIES OR CONDITIONS OF ANYKIND, either express or implied.  
  15.     See the License for the specific languagegoverning 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/beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsd  
  24.   http://activemq.apache.org/schema/corehttp://activemq.apache.org/schema/core/activemq-core.xsd">  
  25.    
  26.   <!-- shutdown hook is disabled as RAR classloader may be gone at shutdown-->  
  27.   <brokerxmlnsbrokerxmlns="http://activemq.apache.org/schema/core"useJmx="true" useShutdownHook="false"brokerName="bruce.broker1">  
  28.    
  29.      <managementContext>  
  30.        <!-- use appserver provided contextinstead of creating one,  
  31.             for jboss use:-Djboss.platform.mbeanserver -->  
  32.        <managementContextcreateConnectormanagementContextcreateConnector="false"/>  
  33.      </managementContext>  
  34.    
  35.     <persistenceAdapter>  
  36.        <kahaDBdirectorykahaDBdirectory="activemq-data/kahadb"/>  
  37.            <!--<jdbcPersistenceAdapterdataSource="#oracle-ds"/>-->  
  38.      </persistenceAdapter>  
  39.    
  40.     <transportConnectors>  
  41.       <transportConnectornametransportConnectorname="bruce.broker1" uri="tcp://localhost:61616"/>  
  42.     </transportConnectors>  
  43.      
  44.   </broker>  
  45. </beans>  
  46.    


 

7.        配置 jboss5,使得jboss5启动的时候能够启动activemq

新建 /default/deploy/activemq-ds.xml 文件,内容如下:

 

  1. <?xmlversionxmlversion="1.0" encoding="UTF-8"?>  
  2.    
  3. <!DOCTYPEconnection-factories  
  4.     PUBLIC "-//JBoss//DTD JBOSS JCA Config5.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.       <track-connection-by-tx/>  
  13.      <rar-name>activemq-ra-5.7.0.rar</rar-name>  
  14.      <connection-definition>javax.jms.QueueConnectionFactory</connection-definition>  
  15.      <ServerUrl>vm://localhost</ServerUrl>  
  16.       <!--  
  17.       <UserName>sa</UserName>  
  18.       <Password></Password>  
  19.       -->  
  20.      <min-pool-size>1</min-pool-size>  
  21.      <max-pool-size>200</max-pool-size>  
  22.      <blocking-timeout-millis>30000</blocking-timeout-millis>  
  23.      <idle-timeout-minutes>3</idle-timeout-minutes>  
  24.    </tx-connection-factory>  
  25.    
  26.    <tx-connection-factory>  
  27.      <jndi-name>activemq/TopicConnectionFactory</jndi-name>  
  28.       <xa-transaction/>  
  29.       <track-connection-by-tx/>  
  30.      <rar-name>activemq-ra-5.7.0.rar</rar-name>  
  31.       <connection-definition>javax.jms.TopicConnectionFactory</connection-definition>  
  32.      <ServerUrl>vm://localhost</ServerUrl>  
  33.       <!--  
  34.       <UserName>sa</UserName>  
  35.       <Password></Password>  
  36.       -->  
  37.      <min-pool-size>1</min-pool-size>  
  38.       <max-pool-size>200</max-pool-size>  
  39.      <blocking-timeout-millis>30000</blocking-timeout-millis>  
  40.      <idle-timeout-minutes>3</idle-timeout-minutes>  
  41.    </tx-connection-factory>  
  42.    
  43.    <mbeancodembeancode="org.jboss.resource.deployment.AdminObject"name="activemq.queue:name=outboundQueue">  
  44.       <attributenameattributename="JNDIName">activemq/queue/outbound</attribute>  
  45.       <dependsoptional-attribute-namedependsoptional-attribute-name="RARName">jboss.jca:service=RARDeployment,name='activemq-ra-5.7.0.rar'</depends>  
  46.       <attributenameattributename="Type">javax.jms.Queue</attribute>  
  47.       <attributenameattributename="Properties">PhysicalName=queue.outbound</attribute>  
  48.    </mbean>  
  49.    
  50.    <mbeancodembeancode="org.jboss.resource.deployment.AdminObject" name="activemq.topic:name=inboundTopic">  
  51.       <attributenameattributename="JNDIName">activemq/topic/inbound</attribute>  
  52.       <dependsoptional-attribute-namedependsoptional-attribute-name="RARName">jboss.jca:service=RARDeployment,name='activemq-ra-5.7.0.rar'</depends>  
  53.       <attributenameattributename="Type">javax.jms.Topic</attribute>  
  54.       <attributenameattributename="Properties">PhysicalName=topic.inbound</attribute>  
  55.    </mbean>  
  56.    
  57. </connection-factories>  


 

 

8.        启动 jboss5

 

 

9.        验证集成成功与否

           a)        安装ANT

           b)        配置ANT环境变量

           c)        启动JBOSS

           d)        打开一个命令窗口,输入

                       cd /apache-activemq-5.3.1/example

                       ant consumer

          e)        打开另外一个命令窗口,输入:

                       cd /apache-activemq-5.3.1/example

                       ant consumer

10.    运行成功

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics