最近项目中需要集成消息中间件来处理消息,选择了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项目**: 首先,使用...
【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(企业版)平台的一个重要组成部分,它...
### Eclipse + JBoss 5 + EJB3 开发指南 #### (1):编写第一个无状态的SessionBean ##### 一、配置开发环境 在开始编写无状态的SessionBean之前,首先需要确保开发环境已经正确配置。以下是所需的主要组件: 1...
本教程主要关注的是如何使用Eclipse集成开发环境(IDE)配合JBossIDE插件以及JBoss应用服务器来搭建一个高效、稳定的Java EE开发环境。接下来,我们将深入探讨这个主题,详细讲解每一个步骤。 一、Eclipse简介 ...
redhat5+jboss4.2.3+apache2.2.19+mod_jk.so集群配置 文档中包括了jkd jboss apache mod_jk 的分别安装步骤,对linux不熟悉的人绝对有所帮助。 我把他搞定中途遇到了很多问题才写了这个文档,相对来说比较完善了,...
【JBOSS7+EJB3.0】是一个关于企业级Java应用服务器JBOSS7与企业JavaBeans(EJB)3.0版本结合使用的实践案例。JBOSS AS(Application Server)是Red Hat公司开发的一款开源Java EE应用服务器,而EJB 3.0是Java平台上...
5. **测试**:通过编写测试用例,确保事务的正确性,检查在异常情况下是否能正确回滚。 通过这种集成,你可以构建出一个高可用、可扩展的企业级应用,能够处理复杂的业务流程,同时保证数据的一致性和完整性。这种...
JBOSS7集成了JAAS(Java Authentication and Authorization Service),允许开发者通过`@RolesAllowed`注解来控制访问权限。 8. **MyEJBProject示例** "MyEJBProject"很可能是用户提供的EJB3项目实例,可能包含了...
首先,我们来看EJB 3.0在JBoss 7.1.1中的集成。EJB 3.0简化了EJB的使用,引入了注解驱动的开发模式,使得开发更为简洁。在JBoss中,EJB容器负责管理Bean的生命周期,提供事务、安全性和并发控制等服务。开发者只需在...
在Linux环境下配置JBoss6.0与JDK7.0是一项关键的任务,因为这两个组件是许多企业级Java应用的基础。JBoss是一个流行的开源应用服务器,它支持Java EE规范,而JDK则是运行Java应用程序和应用服务器所必需的开发工具包...
【JBoss AS7 知识点】 JBoss AS7 是 JBoss 企业应用服务器的一个重要版本...总的来说,JBoss AS7、JBoss Tools 和 Eclipse Indigo 3.7 的集成提供了一个高效且功能齐全的开发和部署环境,极大地提高了开发者的生产力。
### JBoss 6 + mod_jk + Apache 2.2 集群实现 Session 复制详解 #### 一、概述 随着互联网技术的发展与普及,越来越多的企业开始重视Web服务的高可用性和负载均衡能力。在这样的背景下,利用JBoss 6、mod_jk和...