最近项目中需要集成消息中间件来处理消息,选择了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
- <?xmlversionxmlversion="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 informationregarding copyright ownership.
- The ASF licenses this file to You under theApache License, Version 2.0
- (the "License"); you may not usethis 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 agreedto in writing, software
- distributed under the License isdistributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANYKIND, either express or implied.
- See the License for the specific languagegoverning permissions and
- limitations under the License.
- -->
- <connectorxmlnsconnectorxmlns="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 JMSResourceAdapter</description>
- <display-name>ActiveMQ JMS ResourceAdapter</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 informationregarding copyright ownership.
- The ASF licenses this file to You under theApache License, Version 2.0
- (the "License"); you may not usethis 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 agreedto in writing, software
- distributed under the License isdistributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANYKIND, either express or implied.
- See the License for the specific languagegoverning 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 serverthat you want this connection to connect to. If using
- an embedded broker, this valueshould 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 username that will be used to establish connections to the ActiveMQserver.</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 defaultpassword that will be used to log the default user into the ActiveMQserver.</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 idthat will be set on the connection that is established to the ActiveMQserver.</description>
- <config-property-name>Clientid</config-property-name>
- <config-property-type>java.lang.String</config-property-type>
- </config-property>
- <config-property>
- <description>Boolean to configureif outbound connections should reuse the inbound connection's session forsending 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 propertyif you do not wish to deploy an embedded broker -->
- <config-property>
- <description>
- Sets the XML configuration file used toconfigure the embedded ActiveMQ broker via
- Spring if using embedded mode.
- BrokerXmlConfig is the filenamewhich is assumed to be on the classpath unless
- a URL is specified. So a value offoo/bar.xml would be assumed to be on the
- classpath whereasfile:dir/file.xml would use the file system.
- Any valid URL string issupported.
- </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 fromthe root for the RAR
- To use an external file or urllocation
- <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>
6. 配置 activemq (2):修改 broker-config.xml 文件
- <?xmlversionxmlversion="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 informationregarding copyright ownership.
- The ASF licenses this file to You under theApache License, Version 2.0
- (the "License"); you may not usethis 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 agreedto in writing, software
- distributed under the License isdistributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANYKIND, either express or implied.
- See the License for the specific languagegoverning 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/beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsd
- http://activemq.apache.org/schema/corehttp://activemq.apache.org/schema/core/activemq-core.xsd">
- <!-- shutdown hook is disabled as RAR classloader may be gone at shutdown-->
- <brokerxmlnsbrokerxmlns="http://activemq.apache.org/schema/core"useJmx="true" useShutdownHook="false"brokerName="bruce.broker1">
- <managementContext>
- <!-- use appserver provided contextinstead of creating one,
- for jboss use:-Djboss.platform.mbeanserver -->
- <managementContextcreateConnectormanagementContextcreateConnector="false"/>
- </managementContext>
- <persistenceAdapter>
- <kahaDBdirectorykahaDBdirectory="activemq-data/kahadb"/>
- <!--<jdbcPersistenceAdapterdataSource="#oracle-ds"/>-->
- </persistenceAdapter>
- <transportConnectors>
- <transportConnectornametransportConnectorname="bruce.broker1" uri="tcp://localhost:61616"/>
- </transportConnectors>
- </broker>
- </beans>
7. 配置 jboss5,使得jboss5启动的时候能够启动activemq
新建 /default/deploy/activemq-ds.xml 文件,内容如下:
- <?xmlversionxmlversion="1.0" encoding="UTF-8"?>
- <!DOCTYPEconnection-factories
- PUBLIC "-//JBoss//DTD JBOSS JCA Config5.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/>
- <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>
- <mbeancodembeancode="org.jboss.resource.deployment.AdminObject"name="activemq.queue:name=outboundQueue">
- <attributenameattributename="JNDIName">activemq/queue/outbound</attribute>
- <dependsoptional-attribute-namedependsoptional-attribute-name="RARName">jboss.jca:service=RARDeployment,name='activemq-ra-5.7.0.rar'</depends>
- <attributenameattributename="Type">javax.jms.Queue</attribute>
- <attributenameattributename="Properties">PhysicalName=queue.outbound</attribute>
- </mbean>
- <mbeancodembeancode="org.jboss.resource.deployment.AdminObject" name="activemq.topic:name=inboundTopic">
- <attributenameattributename="JNDIName">activemq/topic/inbound</attribute>
- <dependsoptional-attribute-namedependsoptional-attribute-name="RARName">jboss.jca:service=RARDeployment,name='activemq-ra-5.7.0.rar'</depends>
- <attributenameattributename="Type">javax.jms.Topic</attribute>
- <attributenameattributename="Properties">PhysicalName=topic.inbound</attribute>
- </mbean>
- </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. 运行成功
相关推荐
Jboss 7 + EJB 3.0 + Eclipse环境配置
总的来说,“EJB3+JBOSS5+JPA整合”是一个集成了企业级服务、持久化管理和应用服务器的复杂体系,它为企业级Java应用提供了强大的后端支持。开发者需要深入理解EJB3的编程模型、JPA的持久化机制以及JBOSS5的配置和...
【myeclipse+jboss5+shh 搭建框架】是关于集成开发环境Myeclipse、应用服务器JBoss和SSH(Struts1.2、Spring2、Hibernate3.1)三大框架组合使用的教程。以下是详细步骤: 1. **创建Web项目**: 首先,使用...
eclipse + JBoss 5 + EJB3开发指南(转载整理)
【JBOSS+TOMCAT集成开发环境】是一种常见的企业级应用服务器组合,它结合了JBOSS的全面中间件服务和TOMCAT的轻量级Servlet容器特性,为开发者提供了一个高效且灵活的开发与部署平台。在这个“完整版”中,用户可以...
5. **环境配置**:在集成前,需要确保已经安装了JDK,并正确配置了环境变量。对于Eclipse3.7,建议使用JDK 1.7或更高版本。 6. **Drools配置**:在Drools集成后,用户可以在"Preferences"中配置Drools的运行时环境...
5. **验证配置**: - 启动Apache和两个Jboss实例。 - 通过Apache的URL访问应用,如`localhost/test`,如果能够正常访问,表示配置成功。 6. **集群优化**: - 负载均衡:通过worker控制器(如controller)分配...
在本文中,我们将深入探讨如何使用Eclipse集成开发环境(IDE)与JBoss Application Server 5相结合,利用Enterprise JavaBeans(EJB)3.0规范进行应用程序开发。EJB3是Java EE(企业版)平台的一个重要组成部分,它...
2.下载JBOSS,将下载的安装包直接解压到安装目录,假设安装目录在D盘根目录D:\jboss-5.1.0.GA 各个版本链接:http://sourceforge.net/projects/jboss/files/JBoss, 选择JBoss-5.1.0.GA ,2009-05-23 我下载的...
JBOSS7+EJB3.0 例子
本教程主要关注的是如何使用Eclipse集成开发环境(IDE)配合JBossIDE插件以及JBoss应用服务器来搭建一个高效、稳定的Java EE开发环境。接下来,我们将深入探讨这个主题,详细讲解每一个步骤。 一、Eclipse简介 ...
servlet3.0+jboss7+jsp+Mysql5.0+IDEA13 登录注册(jar包,css齐全) 有完整的CSS
Jboss7.1.1+eclipse-kepler开发ejb3 使用eclipse4.3即kepler版本来集成jboss tools工具并使用jboss7.1.1来开发ejb3.1
redhat5+jboss4.2.3+apache2.2.19+mod_jk.so集群配置 文档中包括了jkd jboss apache mod_jk 的分别安装步骤,对linux不熟悉的人绝对有所帮助。 我把他搞定中途遇到了很多问题才写了这个文档,相对来说比较完善了,...
Jboss6+mod_jk+apache2.2集群配置,mod_jk方式的分布式集群方案。
jboss7.1+ejb3.1建立第一个Ejb项目希望可以帮到你
用jbuilder7+jboss3+vss开发EJB
用jbuilder7+jboss3+vss开发EJB
MacOS下jdk1.6+Eclipse4.4.2+JBoss4.2.2+SVN开发环境搭建
[5] 安装 JBoss IDE: 18 [6] 使用 Eclipse 建立第一个 EJB3 Project [ 即 HelloWorld ]: 18 [7] 建立 HelloWorld Stateless Session Bean 及 Local, Remote interfaces: 19 [8] 建立客户端测试程序: 20 [9] ...