---
title: "ActiveMQ5.2.0集成到JBoss4.2.3.GA"
author: "ajavafan2008"
date: "2009-12-24T11:09:00Z"
tags: []
slug: "activemq5-2-0-jboss4-2-3-ga"
draft: false
lastmod: "2014-01-15T10:17:00Z"
id: 2004158
url: "https://gilping.iteye.com/blog/2004158"
---

1、在JBoss的部署目录下建立activemq-ra.rar目录(注意这是一个目录)

2、在ActiveMQ5.2.0的目录X:/apache-activemq-5.2.0/lib/optional下找到activemq-rar- 5.2.0.rar文件，将其全部内容解压缩到第一步建立的目录

3、上面的解压的后，找到META-INF/ra.xml文件，按照下面进行修改

&lt;config-property-value&gt;&lt;/config-property-value&gt;

&lt;!--&lt;config-property-value&gt;xbean:broker-config.xml&lt;/config-property-value&gt; --&gt;

改为

&lt;!--&lt;config-property-value&gt;&lt;/config-property-value&gt; --&gt;

&lt;config-property-value&gt;xbean:broker-config.xml&lt;/config-property-value&gt;

4、配置jboss4.2.3.GA集成ActiveMQ5.2.0的数据源,文件名activemq-ds.xml，内容：

&lt;?xml version="1.0" encoding="UTF-8"?&gt;  
&lt;!DOCTYPE connection-factories  
PUBLIC "-//JBoss//DTD JBOSS JCA Config 1.5//EN"  
"[http://www.jboss.org/j2ee/dtd/jboss-ds\_1\_5.dtd](http://www.jboss.org/j2ee/dtd/jboss-ds_1_5.dtd)"&gt;  
&lt;connection-factories&gt;  
&lt;tx-connection-factory&gt;  
&lt;jndi-name&gt;activemq/QueueConnectionFactory&lt;/jndi-name&gt;  
&lt;xa-transaction/&gt;  
&lt;track-connection-by-tx/&gt;  
&lt;rar-name&gt;activemq-ra.rar&lt;/rar-name&gt;  
&lt;connection-definition&gt;javax.jms.QueueConnectionFactory&lt;/connection-definition&gt;  
&lt;ServerUrl&gt;tcp://localhost:61616&lt;/ServerUrl&gt;  
&lt;min-pool-size&gt;1&lt;/min-pool-size&gt;  
&lt;max-pool-size&gt;200&lt;/max-pool-size&gt;  
&lt;blocking-timeout-millis&gt;30000&lt;/blocking-timeout-millis&gt;  
&lt;idle-timeout-minutes&gt;3&lt;/idle-timeout-minutes&gt;  
&lt;/tx-connection-factory&gt;  
&lt;tx-connection-factory&gt;  
&lt;jndi-name&gt;activemq/TopicConnectionFactory&lt;/jndi-name&gt;  
&lt;xa-transaction/&gt;  
&lt;track-connection-by-tx/&gt;  
&lt;rar-name&gt;activemq-ra.rar&lt;/rar-name&gt;  
&lt;connection-definition&gt;javax.jms.TopicConnectionFactory&lt;/connection-definition&gt;  
&lt;ServerUrl&gt;tcp://localhost:61616&lt;/ServerUrl&gt;  
&lt;min-pool-size&gt;1&lt;/min-pool-size&gt;  
&lt;max-pool-size&gt;200&lt;/max-pool-size&gt;  
&lt;blocking-timeout-millis&gt;30000&lt;/blocking-timeout-millis&gt;  
&lt;idle-timeout-minutes&gt;3&lt;/idle-timeout-minutes&gt;  
&lt;/tx-connection-factory&gt;  
&lt;mbean code="org.jboss.resource.deployment.AdminObject" name="activemq.queue:name=outboundQueue"&gt;  
&lt;attribute name="JNDIName"&gt;activemq/queue/outbound&lt;/attribute&gt;  
&lt;depends optional-attribute-name="RARName"&gt;jboss.jca:service=RARDeployment,name=&apos;activemq-ra.rar&apos;&lt;/depends&gt;  
&lt;attribute name="Type"&gt;javax.jms.Queue&lt;/attribute&gt;  
&lt;attribute name="Properties"&gt;PhysicalName=queue.outbound&lt;/attribute&gt;  
&lt;/mbean&gt;  
&lt;mbean code="org.jboss.resource.deployment.AdminObject" name="activemq.topic:name=inboundTopic"&gt;  
&lt;attribute name="JNDIName"&gt;activemq/topic/inbound&lt;/attribute&gt;  
&lt;depends optional-attribute-name="RARName"&gt;jboss.jca:service=RARDeployment,name=&apos;activemq-ra.rar&apos;&lt;/depends&gt;  
&lt;attribute name="Type"&gt;javax.jms.Topic&lt;/attribute&gt;  
&lt;attribute name="Properties"&gt;PhysicalName=topic.inbound&lt;/attribute&gt;  
&lt;/mbean&gt;  
&lt;/connection-factories&gt;

将此文件复制到jboss的部署目录

5、将X:/apache-activemq-5.2.0/lib/optional下的的以spring-开头的文件、xbean-spring-3.4.jar文件、commons-dbcp-1.2.jar、commons-pool-1.4.jar复制到

x:/jboss-4.2.3.GA/server/default/lib中

6、测试运行，注意查看jboss控制台，有类似以下内容

12:17:21,538 INFO \[RARDeployment] Required license terms exist, view META-INF/r  
a.xml in .../deploy/activemq-ra.rar/  
12:17:21,677 INFO \[ResourceXmlApplicationContext] Refreshing org.apache.xbean.s  
[pring.context.ResourceXmlApplicationContext@2d4c7e](mailto:pring.context.ResourceXmlApplicationContext@2d4c7e): display name [org.apache.xbe  
[an.spring.context.ResourceXmlApplicationContext@2d4c7e](mailto:an.spring.context.ResourceXmlApplicationContext@2d4c7e)]; startup date [Mon Jan 1  
9 12:17:21 CST 2009]; root of context hierarchy  
12:17:21,771 INFO \[XBeanXmlBeanDefinitionReader] Loading XML bean definitions f  
rom class path resource \[broker-config.xml]  
12:17:22,008 INFO \[ResourceXmlApplicationContext] Bean factory for application  
context \[org.apache.xbean.spring.context.ResourceXmlApplicationContext@2d4c7e]:  
[org.springframework.beans.factory.support.DefaultListableBeanFactory@17777a1](mailto:org.springframework.beans.factory.support.DefaultListableBeanFactory@17777a1)  
12:17:22,024 INFO \[DefaultListableBeanFactory] Pre-instantiating singletons in  
[org.springframework.beans.factory.support.DefaultListableBeanFactory@17777a1](mailto:org.springframework.beans.factory.support.DefaultListableBeanFactory@17777a1): de  
fining beans \[org.apache.activemq.xbean.XBeanBrokerService#0]; root of factory h  
ierarchy  
12:17:23,284 INFO \[BrokerService] Using Persistence Adapter: JournalPersistence  
Adapator(JDBCPersistenceAdaptor([org.apache.derby.jdbc.EmbeddedDataSource@8d539f](mailto:org.apache.derby.jdbc.EmbeddedDataSource@8d539f))  
)

7、配置消息持久化数据库，使用以下内容替换broker-config.xml文件内容，注意配置数据库连接参数，以及将jdbc驱动库文件拷贝到jboss/server/default/lib目录中

&lt;!--  
Licensed to the Apache Software Foundation (ASF) under one or more  
contributor license agreements. See the NOTICE file distributed with  
this work for additional information regarding copyright ownership.  
The ASF licenses this file to You under the Apache License, Version  
2.0 (the "License"); you may not use this file except in compliance  
with the License. You may obtain a copy of the License at

[http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0) Unless required by  
applicable law or agreed to in writing, software distributed under the  
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR  
CONDITIONS OF ANY KIND, either express or implied. See the License for  
the specific language governing permissions and limitations under the  
License.  
\--&gt;  
&lt;!-- START SNIPPET: example --&gt;  
&lt;beans xmlns="[http://www.springframework.org/schema/beans](http://www.springframework.org/schema/beans)"  
xmlns:amq="[http://activemq.apache.org/schema/core](http://activemq.apache.org/schema/core)" xmlns:xsi="[http://www.w3.org/2001/XMLSchema-instance](http://www.w3.org/2001/XMLSchema-instance)"  
xsi:schemaLocation="[http://www.springframework.org/schema/beans](http://www.springframework.org/schema/beans) [http://www.springframework.org/schema/beans/spring-beans-2.0.xsd](http://www.springframework.org/schema/beans/spring-beans-2.0.xsd)  
[http://activemq.apache.org/schema/core](http://activemq.apache.org/schema/core) [http://activemq.apache.org/schema/core/activemq-core.xsd](http://activemq.apache.org/schema/core/activemq-core.xsd)  
[http://activemq.apache.org/camel/schema/spring](http://activemq.apache.org/camel/schema/spring) [http://activemq.apache.org/camel/schema/spring/camel-spring.xsd](http://activemq.apache.org/camel/schema/spring/camel-spring.xsd)"&gt;

&lt;!--  
Allows us to use system properties as variables in this configuration  
file  
\--&gt;  
&lt;!--  
&lt;bean  
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&gt;  
&lt;property name="locations"&gt;  
&lt;value&gt;file:${activemq.base}/conf/credentials.properties &lt;/value&gt;  
&lt;/property&gt; &lt;/bean&gt;  
\--&gt;

&lt;broker xmlns="[http://activemq.apache.org/schema/core](http://activemq.apache.org/schema/core)"  
brokerName="localhost" dataDirectory="../data"&gt;

&lt;!--  
Destination specific policies using destination names or wildcards  
\--&gt;  
&lt;destinationPolicy&gt;  
&lt;policyMap&gt;  
&lt;policyEntries&gt;  
&lt;policyEntry queue="&gt;" memoryLimit="5mb" /&gt;  
&lt;policyEntry topic="&gt;" memoryLimit="5mb"&gt;  
&lt;!--  
you can add other policies too such as these &lt;dispatchPolicy&gt;  
&lt;strictOrderDispatchPolicy/&gt; &lt;/dispatchPolicy&gt;  
&lt;subscriptionRecoveryPolicy&gt;  
&lt;lastImageSubscriptionRecoveryPolicy/&gt;  
&lt;/subscriptionRecoveryPolicy&gt;  
\--&gt;  
&lt;/policyEntry&gt;  
&lt;/policyEntries&gt;  
&lt;/policyMap&gt;  
&lt;/destinationPolicy&gt;

&lt;!-- Use the following to configure how ActiveMQ is exposed in JMX --&gt;  
&lt;managementContext&gt;  
&lt;managementContext createConnector="false" /&gt;  
&lt;/managementContext&gt;

&lt;transportConnectors&gt;  
&lt;!--  
prefixing a connector with discovery: causes the connector to be  
advertiesed over rendezvous  
\--&gt;  
&lt;transportConnector uri="tcp://localhost:61616"  
discoveryUri="multicast://default" /&gt;  
&lt;/transportConnectors&gt;

&lt;networkConnectors&gt;  
&lt;!-- by default just auto discover the other brokers --&gt;  
&lt;networkConnector uri="multicast://default" /&gt;  
&lt;!--  
&lt;networkConnector  
uri="static://(tcp://host1:61616,tcp://host2:61616)"/&gt;  
\--&gt;  
&lt;/networkConnectors&gt;

&lt;!--  
&lt;persistenceAdapter&gt; &lt;amqPersistenceAdapter syncOnWrite="false"  
directory="../data" maxFileLength="20 mb" /&gt; &lt;/persistenceAdapter&gt;  
\--&gt;  
&lt;!--  
Use the following if you wish to configure the journal with JDBC  
\--&gt;  
&lt;!--  
&lt;persistenceAdapter&gt; &lt;journaledJDBC  
dataDirectory="${activemq.base}/data" dataSource="#postgres-ds"/&gt;  
&lt;/persistenceAdapter&gt;  
\--&gt;

&lt;!-- Or if you want to use pure JDBC without a journal --&gt;  
&lt;!----&gt;  
&lt;persistenceAdapter&gt;  
&lt;jdbcPersistenceAdapter dataSource="#mysql-ds" /&gt;  
&lt;/persistenceAdapter&gt;

&lt;!--  
&lt;sslContext&gt; &lt;sslContext  
keyStore="file:${activemq.base}/conf/broker.ks"  
keyStorePassword="password"  
trustStore="file:${activemq.base}/conf/broker.ts"  
trustStorePassword="password"/&gt; &lt;/sslContext&gt;  
\--&gt;

&lt;!--  
The maximum about of space the broker will use before slowing down  
producers  
\--&gt;  
&lt;systemUsage&gt;  
&lt;systemUsage&gt;  
&lt;memoryUsage&gt;  
&lt;memoryUsage limit="20 mb" /&gt;  
&lt;/memoryUsage&gt;  
&lt;storeUsage&gt;  
&lt;storeUsage limit="1 gb" name="foo" /&gt;  
&lt;/storeUsage&gt;  
&lt;tempUsage&gt;  
&lt;tempUsage limit="100 mb" /&gt;  
&lt;/tempUsage&gt;  
&lt;/systemUsage&gt;  
&lt;/systemUsage&gt;

&lt;!--  
The transport connectors ActiveMQ will listen to  
&lt;transportConnectors&gt; &lt;transportConnector name="openwire"  
uri="tcp://localhost:61616" discoveryUri="multicast://default" /&gt;  
&lt;transportConnector name="ssl" uri="ssl://localhost:61617" /&gt;  
&lt;transportConnector name="stomp" uri="stomp://localhost:61613" /&gt;  
&lt;transportConnector name="xmpp" uri="xmpp://localhost:61222" /&gt;  
&lt;/transportConnectors&gt;  
\--&gt;  
&lt;/broker&gt;

&lt;!--  
\** Lets deploy some Enterprise Integration Patterns inside the  
ActiveMQ Message Broker \** For more details see \** \**  
[http://activemq.apache.org/enterprise-integration-patterns.html](http://activemq.apache.org/enterprise-integration-patterns.html)  
\--&gt;  
&lt;!--  
&lt;camelContext id="camel"  
xmlns="[http://activemq.apache.org/camel/schema/spring](http://activemq.apache.org/camel/schema/spring)"&gt;

&lt;package&gt;org.foo.bar&lt;/package&gt; &lt;route&gt; &lt;from uri="activemq:example.A"  
/&gt; &lt;to uri="activemq:example.B" /&gt; &lt;/route&gt; &lt;/camelContext&gt;  
\--&gt;  
&lt;!--  
\** Lets configure some Camel endpoints \** \**  
[http://activemq.apache.org/camel/components.html](http://activemq.apache.org/camel/components.html)  
\--&gt;

&lt;!--  
configure the camel activemq component to use the current broker &lt;bean  
id="activemq"  
class="org.apache.activemq.camel.component.ActiveMQComponent"&gt;  
&lt;property name="connectionFactory"&gt; &lt;bean  
class="org.apache.activemq.ActiveMQConnectionFactory"&gt; &lt;property  
name="brokerURL"  
value="vm://localhost?create=false&amp;waitForStart=10000" /&gt;  
&lt;property name="userName" value="${activemq.username}" /&gt; &lt;property  
name="password" value="${activemq.password}" /&gt; &lt;/bean&gt; &lt;/property&gt;  
&lt;/bean&gt;  
\--&gt;

&lt;!--  
Uncomment to create a command agent to respond to message based admin  
commands on the ActiveMQ.Agent topic  
\--&gt;  
&lt;!--  
&lt;commandAgent xmlns="[http://activemq.apache.org/schema/core](http://activemq.apache.org/schema/core)"  
brokerUrl="vm://localhost" username="${activemq.username}"  
password="${activemq.password}"/&gt;  
\--&gt;

&lt;!--  
An embedded servlet engine for serving up the Admin console &lt;jetty  
xmlns="[http://mortbay.com/schemas/jetty/1.0](http://mortbay.com/schemas/jetty/1.0)"&gt; &lt;connectors&gt;  
&lt;nioConnector port="8161" /&gt; &lt;/connectors&gt; &lt;handlers&gt; &lt;webAppContext  
contextPath="/admin" resourceBase="${activemq.base}/webapps/admin"  
logUrlOnStart="true" /&gt; &lt;webAppContext contextPath="/demo"  
resourceBase="${activemq.base}/webapps/demo" logUrlOnStart="true" /&gt;  
&lt;webAppContext contextPath="/fileserver"  
resourceBase="${activemq.base}/webapps/fileserver"  
logUrlOnStart="true" /&gt; &lt;/handlers&gt; &lt;/jetty&gt;  
\--&gt;  
&lt;!--  
This xbean configuration file supports all the standard spring xml  
configuration options  
\--&gt;

&lt;!-- Postgres DataSource Sample Setup --&gt;  
&lt;!--  
&lt;bean id="postgres-ds" class="org.postgresql.ds.PGPoolingDataSource"&gt;  
&lt;property name="serverName" value="localhost"/&gt; &lt;property  
name="databaseName" value="activemq"/&gt; &lt;property name="portNumber"  
value="0"/&gt; &lt;property name="user" value="activemq"/&gt; &lt;property  
name="password" value="activemq"/&gt; &lt;property name="dataSourceName"  
value="postgres"/&gt; &lt;property name="initialConnections" value="1"/&gt;  
&lt;property name="maxConnections" value="10"/&gt; &lt;/bean&gt;  
\--&gt;

&lt;!-- MySql DataSource Sample Setup --&gt;  
&lt;!----&gt;  
&lt;bean id="mysql-ds" class="org.apache.commons.dbcp.BasicDataSource"  
destroy-method="close"&gt;  
&lt;property name="driverClassName" value="com.mysql.jdbc.Driver" /&gt;  
&lt;property name="url"  
value="jdbc:mysql://localhost:3306/mydb?characterEncoding=utf-8&amp;relaxAutoCommit=true" /&gt;  
&lt;property name="username" value="root" /&gt;  
&lt;property name="password" value="root" /&gt;  
&lt;property name="maxActive" value="200" /&gt;  
&lt;property name="poolPreparedStatements" value="true" /&gt;  
&lt;/bean&gt;

&lt;!-- Oracle DataSource Sample Setup --&gt;  
&lt;!--  
&lt;bean id="oracle-ds" class="org.apache.commons.dbcp.BasicDataSource"  
destroy-method="close"&gt; &lt;property name="driverClassName"  
value="oracle.jdbc.driver.OracleDriver"/&gt; &lt;property name="url"  
value="jdbc:oracle:thin:@localhost:1521:AMQDB"/&gt; &lt;property  
name="username" value="scott"/&gt; &lt;property name="password"  
value="tiger"/&gt; &lt;property name="maxActive" value="200"/&gt; &lt;property  
name="poolPreparedStatements" value="true"/&gt; &lt;/bean&gt;  
\--&gt;

&lt;!-- Embedded Derby DataSource Sample Setup --&gt;  
&lt;!--  
&lt;bean id="derby-ds" class="org.apache.derby.jdbc.EmbeddedDataSource"&gt;  
&lt;property name="databaseName" value="derbydb"/&gt; &lt;property  
name="createDatabase" value="create"/&gt; &lt;/bean&gt;  
\--&gt;

&lt;/beans&gt;  
&lt;!-- END SNIPPET: example --&gt;

本文来自CSDN博客，转载请标明出处：[http://blog.csdn.net/xiaoming444/archive/2009/02/27/3942803.aspx](http://blog.csdn.net/xiaoming444/archive/2009/02/27/3942803.aspx)