测试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文件,修改配置如下:
- <?xml version="1.0" encoding="UTF-8"?>
- <!--
- 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
- 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.
- -->
- <connector xmlns="http://java.sun.com/xml/ns/j2ee"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
- http://java.sun.com/xml/ns/j2ee/connector_1_5.xsd"
- version="1.5">
- <description>ActiveMQ inbound and outbound JMS ResourceAdapter</description>
- <display-name>ActiveMQ JMS Resource Adapter</display-name>
- <vendor-name>activemq.org</vendor-name>
- <eis-type>JMS 1.1</eis-type>
- <resourceadapter-version>1.0</resourceadapter-version>
- <license>
- <description>
- 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
- 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.
- </description>
- <license-required>true</license-required>
- </license>
- <resourceadapter>
- <resourceadapter-class>org.apache.activemq.ra.ActiveMQResourceAdapter</resourceadapter-class>
- <config-property>
- <description>
- The URL to the ActiveMQ server that you want this connection to connect to. If using
- an embedded broker, this value should be 'vm://localhost'.
- </description>
- <config-property-name>ServerUrl</config-property-name>
- <config-property-type>java.lang.String</config-property-type>
- <!--<config-property-value>tcp://localhost:61616</config-property-value>-->
- <config-property-value>vm://localhost</config-property-value>
- </config-property>
- <config-property>
- <description>The default user name that will be used to establish connections to the ActiveMQ server.</description>
- <config-property-name>UserName</config-property-name>
- <config-property-type>java.lang.String</config-property-type>
- <config-property-value>defaultUser</config-property-value>
- </config-property>
- <config-property>
- <description>The default password that will be used to log the default user into the ActiveMQ server.</description>
- <config-property-name>Password</config-property-name>
- <config-property-type>java.lang.String</config-property-type>
- <config-property-value>defaultPassword</config-property-value>
- </config-property>
- <config-property>
- <description>The client id that will be set on the connection that is established to the ActiveMQ server.</description>
- <config-property-name>Clientid</config-property-name>
- <config-property-type>java.lang.String</config-property-type>
- </config-property>
- <config-property>
- <description>Boolean to configure if outbound connections should reuse the inbound connection's session for sending messages.</description>
- <config-property-name>UseInboundSession</config-property-name>
- <config-property-type>java.lang.Boolean</config-property-type>
- <config-property-value>false</config-property-value>
- </config-property>
- <!-- NOTE disable the following property if you do not wish to deploy an embedded broker -->
- <config-property>
- <description>
- Sets the XML configuration file used to configure the embedded ActiveMQ broker via
- Spring if using embedded mode.
- BrokerXmlConfig is the filename which is assumed to be on the classpath unless
- a URL is specified. So a value of foo/bar.xml would be assumed to be on the
- classpath whereas file:dir/file.xml would use the file system.
- Any valid URL string is supported.
- </description>
- <config-property-name>BrokerXmlConfig</config-property-name>
- <config-property-type>java.lang.String</config-property-type>
- <!--<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>
- -->
- </config-property>
- <outbound-resourceadapter>
- <connection-definition>
- <managedconnectionfactory-class>org.apache.activemq.ra.ActiveMQManagedConnectionFactory</managedconnectionfactory-class>
- <connectionfactory-interface>javax.jms.ConnectionFactory</connectionfactory-interface>
- <connectionfactory-impl-class>org.apache.activemq.ra.ActiveMQConnectionFactory</connectionfactory-impl-class>
- <connection-interface>javax.jms.Connection</connection-interface>
- <connection-impl-class>org.apache.activemq.ra.ManagedConnectionProxy</connection-impl-class>
- </connection-definition>
- <connection-definition>
- <managedconnectionfactory-class>org.apache.activemq.ra.ActiveMQManagedConnectionFactory</managedconnectionfactory-class>
- <connectionfactory-interface>javax.jms.QueueConnectionFactory</connectionfactory-interface>
- <connectionfactory-impl-class>org.apache.activemq.ra.ActiveMQConnectionFactory</connectionfactory-impl-class>
- <connection-interface>javax.jms.QueueConnection</connection-interface>
- <connection-impl-class>org.apache.activemq.ra.ManagedConnectionProxy</connection-impl-class>
- </connection-definition>
- <connection-definition>
- <managedconnectionfactory-class>org.apache.activemq.ra.ActiveMQManagedConnectionFactory</managedconnectionfactory-class>
- <connectionfactory-interface>javax.jms.TopicConnectionFactory</connectionfactory-interface>
- <connectionfactory-impl-class>org.apache.activemq.ra.ActiveMQConnectionFactory</connectionfactory-impl-class>
- <connection-interface>javax.jms.TopicConnection</connection-interface>
- <connection-impl-class>org.apache.activemq.ra.ManagedConnectionProxy</connection-impl-class>
- </connection-definition>
- <transaction-support>XATransaction</transaction-support>
- <authentication-mechanism>
- <authentication-mechanism-type>BasicPassword</authentication-mechanism-type>
- <credential-interface>javax.resource.spi.security.PasswordCredential</credential-interface>
- </authentication-mechanism>
- <reauthentication-support>false</reauthentication-support>
- </outbound-resourceadapter>
- <inbound-resourceadapter>
- <messageadapter>
- <messagelistener>
- <messagelistener-type>javax.jms.MessageListener</messagelistener-type>
- <activationspec>
- <activationspec-class>org.apache.activemq.ra.ActiveMQActivationSpec</activationspec-class>
- <required-config-property>
- <config-property-name>destination</config-property-name>
- </required-config-property>
- <required-config-property>
- <config-property-name>destinationType</config-property-name>
- </required-config-property>
- </activationspec>
- </messagelistener>
- </messageadapter>
- </inbound-resourceadapter>
- <adminobject>
- <adminobject-interface>javax.jms.Queue</adminobject-interface>
- <adminobject-class>org.apache.activemq.command.ActiveMQQueue</adminobject-class>
- <config-property>
- <config-property-name>PhysicalName</config-property-name>
- <config-property-type>java.lang.String</config-property-type>
- </config-property>
- </adminobject>
- <adminobject>
- <adminobject-interface>javax.jms.Topic</adminobject-interface>
- <adminobject-class>org.apache.activemq.command.ActiveMQTopic</adminobject-class>
- <config-property>
- <config-property-name>PhysicalName</config-property-name>
- <config-property-type>java.lang.String</config-property-type>
- </config-property>
- </adminobject>
- </resourceadapter>
- </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文件,修改配置如下:
- <?xml version="1.0" encoding="UTF-8"?>
- <!--
- 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
- 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.
- -->
- <!-- START SNIPPET: xbean -->
- <beans
- xmlns="http://www.springframework.org/schema/beans"
- xmlns:amq="http://activemq.apache.org/schema/core"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
- http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">
- <!-- shutdown hook is disabled as RAR classloader may be gone at shutdown -->
- <broker xmlns="http://activemq.apache.org/schema/core" useJmx="true" useShutdownHook="false" brokerName="bruce.broker1">
- <managementContext>
- <!-- use appserver provided context instead of creating one,
- for jboss use: -Djboss.platform.mbeanserver -->
- <managementContext createConnector="false"/>
- </managementContext>
- <persistenceAdapter>
- <kahaDB directory="activemq-data/kahadb"/>
- <!--<jdbcPersistenceAdapter dataSource="#oracle-ds"/>-->
- </persistenceAdapter>
- <transportConnectors>
- <transportConnector name="bruce.broker1" uri="tcp://192.168.24.148:61616"/>
- </transportConnectors>
- </broker>
- </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文件,添加内容如下:
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE connection-factories
- PUBLIC "-//JBoss//DTD JBOSS JCA Config 5.0//EN"
- "http://www.jboss.org/j2ee/dtd/jboss-ds_5_0.dtd">
- <connection-factories>
- <tx-connection-factory>
- <jndi-name>activemq/QueueConnectionFactory</jndi-name>
- <xa-transaction/>
- <!--<use-java-context>false</use-java-context>-->
- <track-connection-by-tx/>
- <rar-name>activemq-ra-5.7.0.rar</rar-name>
- <connection-definition>javax.jms.QueueConnectionFactory</connection-definition>
- <ServerUrl>vm://localhost</ServerUrl>
- <!--
- <UserName>sa</UserName>
- <Password></Password>
- -->
- <min-pool-size>1</min-pool-size>
- <max-pool-size>200</max-pool-size>
- <blocking-timeout-millis>30000</blocking-timeout-millis>
- <idle-timeout-minutes>3</idle-timeout-minutes>
- </tx-connection-factory>
- <tx-connection-factory>
- <jndi-name>activemq/TopicConnectionFactory</jndi-name>
- <xa-transaction/>
- <track-connection-by-tx/>
- <rar-name>activemq-ra-5.7.0.rar</rar-name>
- <connection-definition>javax.jms.TopicConnectionFactory</connection-definition>
- <ServerUrl>vm://localhost</ServerUrl>
- <!--
- <UserName>sa</UserName>
- <Password></Password>
- -->
- <min-pool-size>1</min-pool-size>
- <max-pool-size>200</max-pool-size>
- <blocking-timeout-millis>30000</blocking-timeout-millis>
- <idle-timeout-minutes>3</idle-timeout-minutes>
- </tx-connection-factory>
- <mbean code="org.jboss.resource.deployment.AdminObject" name="activemq.queue:name=outboundQueue">
- <attribute name="JNDIName">activemq/queue/outbound</attribute>
- <depends optional-attribute-name="RARName">jboss.jca:service=RARDeployment,name='activemq-ra-5.7.0.rar'</depends>
- <attribute name="Type">javax.jms.Queue</attribute>
- <attribute name="Properties">PhysicalName=queue.outbound</attribute>
- </mbean>
- <mbean code="org.jboss.resource.deployment.AdminObject" name="activemq.topic:name=inboundTopic">
- <attribute name="JNDIName">activemq/topic/inbound</attribute>
- <depends optional-attribute-name="RARName">jboss.jca:service=RARDeployment,name='activemq-ra-5.7.0.rar'</depends>
- <attribute name="Type">javax.jms.Topic</attribute>
- <attribute name="Properties">PhysicalName=topic.inbound</attribute>
- </mbean>
- </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'
成功!