ActiveMQ学习笔记----把ActiveMQ 4.x 集成到JBoss 4.x 中

在Java领域中,把某一产品集成到应用服务器中是很常见的,而把消息中间件集成到应用服务器中就更常见了。
目前开源应用服务器中应用较广的是Geronimo和JBoss。Geronimo 默认的JMS Provider就是ActiveMQ,而JBoss应用服务器默认的JMS Provider则是JBossMQ。把ActiveMQ集成到JBoss中是一个很常见的需求。如果你也有把ActiveMQ集成到JBoss中的需求,就请你好好阅读下面的内容。本文介绍的集成方法适用于Windows,Solaris和Unix平台。


一.集成所需的环境
Sun Java jdk1.5+
RedHat JBoss-4.0.5.GA+
Apache apache-activemq-4.1.1.zip

说明:
1.jdk必须使用1.5以上的版本,如果使用1.4或更早的版本,会在控制台抛出异常,提示某些class无法找到。
2.apache-activemq-4.1.1.zip是在Apache网站上下载的压缩包,应该先解压缩。在解压后的/apache-activemq-4.1.1/lib/optional文件夹中找到activemq-rar-4.1.1.rar,这个是我们和JBossMQ集成所用的包。
3.在把ActiveMQ集成到JBoss之前,应确保JBoss能够正确的启动。
二.具体集成步骤
1.安装jdk1.5
安装jdk1.5,并保证其能正确运行。

2.安装JBoss应用服务器
安装JBoss应用服务器,并使其在集成ActiveMQ之前正常运行。
使用下面的命令来启动JBoss服务器:
$ cd jboss-4.0.5.GA
$ ./bin/run.sh -c default
JBoss正常启动后,控制台会打印如下信息:
=========================================================================

JBoss Bootstrap Environment

JBOSS_HOME: /opt/jboss-4.0.5.GA

JAVA: java

JAVA_OPTS: -server -Xms128m -Xmx512m -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000 -Dprogram.name=run.sh

CLASSPATH: /opt/jboss-4.0.5.GA/bin/run.jar:/lib/tools.jar

=========================================================================

15:34:47,999 INFO [Server] Starting JBoss (MX MicroKernel)...
15:34:48,001 INFO [Server] Release ID: JBoss [Zion] 4.0.5.GA (build: CVSTag=JBoss_4_0_4_GA date=200605151000)
15:34:48,004 INFO [Server] Home Dir: /opt/jboss-4.0.5.GA
15:34:48,005 INFO [Server] Home URL: file:/opt/jboss-4.0.5.GA/
15:34:48,007 INFO [Server] Patch URL: null
15:34:48,007 INFO [Server] Server Name: default
15:34:48,007 INFO [Server] Server Home Dir: /opt/jboss-4.0.5.GA/server/default
15:34:48,011 INFO [Server] Server Home URL: file:/opt/jboss-4.0.5.GA/server/default/
15:34:48,012 INFO [Server] Server Log Dir: /opt/jboss-4.0.5.GA/server/default/log
15:34:48,017 INFO [Server] Server Temp Dir: /opt/jboss-4.0.5.GA/server/default/tmp
15:34:48,022 INFO [Server] Root Deployment Filename: jboss-service.xml
...
15:35:17,360 INFO [Server] JBoss (MX MicroKernel) [4.0.5.GA (build: CVSTag=JBoss_4_0_4_GA date=200605151000)] Started in 22s:238ms

3.集成ActiveMQ

3.1 解压activemq-rar-4.1.1.rar
解压activemq-rar-4.1.1.rar到文件夹activemq-ra.rar(注意:activemq-ra.rar是文件夹名)下,解压后activemq-ra.rar文件夹下包含以下内容:
META-INF
activeio-core-3.0.0-incubator.jar
activemq-core-4.1.1.jar
activemq-ra-4.1.1.jar
backport-util-concurrent-2.1.jar
broker-config.xml
commons-logging-1.0.3.jar
derby-10.1.1.0.jar
geronimo-j2ee-management_1.0_spec-1.0.jar
log4j-1.2.12.jar
spring-2.0.jar
xbean-spring-2.8.jar
然后把activemq-ra.rar文件夹拷贝到JBoss服务器的jboss-4.0.5.GA/server/default/deploy/目录下。

3.2 修改activemq-ra.rar文件中的META-INF/ra.xml文件
修改activemq-ra.rar文件中的META-INF/ra.xml文件,具体修改方法如下:
初始配置:
<!-- NOTE disable the following property if you do not wish to deploy an embedded broker -->
<config-property>
<description>
......
</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>
-->
</config-property>
修改后的配置:
<!-- NOTE disable the following property if you do not wish to deploy an embedded broker -->
<config-property>
<description>
......
</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>
</config-property>

通过修改ra.xml文件的<config-property>属性,让JBoss使用activemq-ra.rar文件夹下的broker-config.xml作为默认的配置文件来对ActiveMQ进行配置

3.3 修改activemq-ra.rar文件夹下borker-config.xml
borker-config.xml的修改方法如下:
初始配置:
<beans xmlns="http://activemq.org/config/1.0">
<broker useJmx="true">
修改后的配置:
<beans>
<broker useJmx="true" xmlns="http://activemq.org/config/1.0">

3.4 将activemq-ra.rar文件夹中的xbean-spring-2.8.jar拷贝到JBoss服务器的jboss-4.0.5.GA/server/default/lib目录下

3.5 编写activemq-ds.xml文件,放在JBoss应用服务器的jboss-4.0.5.GA/server/default/depoly/目录下
activemq-ds.xml的代码如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE connection-factories
PUBLIC "-//JBoss//DTD JBOSS JCA Config 1.5//EN"
"http://www.jboss.org/j2ee/dtd/jboss-ds_1_5.dtd">

<connection-factories>
<tx-connection-factory>
<jndi-name>activemq/QueueConnectionFactory</jndi-name>
<xa-transaction/>
<track-connection-by-tx/>
<rar-name>activemq-ra.rar</rar-name>
<connection-definition>javax.jms.QueueConnectionFactory</connection-definition>
<ServerUrl>tcp://localhost:61616</ServerUrl>
<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.rar</rar-name>
<connection-definition>javax.jms.TopicConnectionFactory</connection-definition>
<ServerUrl>tcp://localhost:61616</ServerUrl>
<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=&apos;activemq-ra.rar&apos;</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=&apos;activemq-ra.rar&apos;</depends>
<attribute name="Type">javax.jms.Topic</attribute>
<attribute name="Properties">PhysicalName=topic.inbound</attribute>
</mbean>
</connection-factories>

三.重新启动JBoss,看配置是否成功
重新启动JBoss,会在控制台中看到如下信息:
=========================================================================

JBoss Bootstrap Environment

JBOSS_HOME: /opt/jboss

JAVA: java

JAVA_OPTS: -server -Xms128m -Xmx512m -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000 -Dprogram.name=run.sh

CLASSPATH: /opt/jboss/bin/run.jar:/lib/tools.jar

=========================================================================

22:55:48,686 INFO [Server] Starting JBoss (MX MicroKernel)...
22:55:48,688 INFO [Server] Release ID: JBoss [Zion] 4.0.5.GA (build: CVSTag=JBoss_4_0_5_GA date=200605151000)
22:55:48,690 INFO [Server] Home Dir: /opt/jboss-4.0.5.GA
22:55:48,692 INFO [Server] Home URL: file:/opt/jboss-4.0.5.GA/
22:55:48,695 INFO [Server] Patch URL: null
22:55:48,697 INFO [Server] Server Name: default
22:55:48,698 INFO [Server] Server Home Dir: /opt/jboss-4.0.5.GA/server/default
22:55:48,701 INFO [Server] Server Home URL: file:/opt/jboss-4.0.5.GA/server/default/
22:55:48,702 INFO [Server] Server Log Dir: /opt/jboss-4.0.5.GA/server/default/log
22:55:48,704 INFO [Server] Server Temp Dir: /opt/jboss-4.0.5.GA/server/default/tmp
22:55:48,706 INFO [Server] Root Deployment Filename: jboss-service.xml
22:55:49,092 INFO [ServerInfo] Java version: 1.5.0_06,Apple Computer, Inc.
22:55:49,101 INFO [ServerInfo] Java VM: Java HotSpot(TM) Server VM 1.5.0_06-64,"Apple Computer, Inc."
22:55:49,102 INFO [ServerInfo] OS-System: Mac OS X 10.4.8,i386
22:55:49,803 INFO [Server] Core system initialized
22:55:53,379 INFO [WebService] Using RMI server codebase: http://rattlesnake:8083/
22:55:53,400 INFO [Log4jService$URLWatchTimerTask] Configuring from URL: resource:log4j.xml
22:55:54,034 INFO [NamingService] JNDI bootstrap JNP=/0.0.0.0:1099, RMI=/0.0.0.0:1098, backlog=50, no client SocketFactory, Server SocketFactory=class
org.jboss.net.sockets.DefaultSocketFactory
22:55:58,475 INFO [Embedded] Catalina naming disabled
22:55:58,566 INFO [ClusterRuleSetFactory] Unable to find a cluster rule set in the classpath. Will load the default rule set.
22:55:58,569 INFO [ClusterRuleSetFactory] Unable to find a cluster rule set in the classpath. Will load the default rule set.
22:55:59,110 INFO [Http11BaseProtocol] Initializing Coyote HTTP/1.1 on http-0.0.0.0-8080
22:55:59,114 INFO [Catalina] Initialization processed in 545 ms
22:55:59,116 INFO [StandardService] Starting service jboss.web
22:55:59,121 INFO [StandardEngine] Starting Servlet Engine: Apache Tomcat/5.5.17
22:55:59,179 INFO [StandardHost] XML validation disabled
22:55:59,221 INFO [Catalina] Server startup in 105 ms
22:55:59,600 INFO [TomcatDeployer] deploy, ctxPath=/invoker, warUrl=.../deploy/http-invoker.sar/invoker.war/
22:55:59,874 INFO [WebappLoader] Dual registration of jndi stream handler: factory already defined
22:56:00,899 INFO [TomcatDeployer] deploy, ctxPath=/, warUrl=.../deploy/jbossweb-tomcat55.sar/ROOT.war/
22:56:01,700 INFO [TomcatDeployer] deploy, ctxPath=/jbossws, warUrl=.../tmp/deploy/tmp60528jbossws-exp.war/
22:56:01,891 INFO [SubscriptionManager] Bound event dispatcher to java:/EventDispatcher
22:56:02,203 INFO [TomcatDeployer] deploy, ctxPath=/jbossmq-httpil, warUrl=.../deploy/jms/jbossmq-httpil.sar/jbossmq-httpil.war/
22:56:04,546 INFO [TomcatDeployer] deploy, ctxPath=/web-console, warUrl=.../deploy/management/console-mgr.sar/web-console.war/
22:56:05,690 INFO [MailService] Mail Service bound to java:/Mail
22:56:07,215 INFO [RARDeployment] Required license terms exist, view META-INF/ra.xml in .../deploy/activemq-ra.rar/
22:56:07,452 INFO [XBeanXmlBeanDefinitionReader] Loading XML bean definitions from class path resource [broker-config.xml]
22:56:07,750 INFO [ClassPathXmlApplicationContext] Bean factory for application context [org.apache.xbean.spring.context.ClassPathXmlApplicationContext;hashCode=13887543]:
org.springframework.beans.factory.support.DefaultListableBeanFactory defining
beans [org.apache.activemq.xbean.XBeanBrokerService]; root of BeanFactory hierarchy
22:56:07,765 INFO [ClassPathXmlApplicationContext] 1 beans defined in application context
[org.apache.xbean.spring.context.ClassPathXmlApplicationContext;hashCode=13887543]
22:56:07,773 INFO [CollectionFactory] JDK 1.4+ collections available
22:56:07,778 INFO [ClassPathXmlApplicationContext] Unable to locate MessageSource with name &apos;messageSource&apos;: using default
[org.springframework.context.support.DelegatingMessageSource@5fee96]
22:56:07,781 INFO [ClassPathXmlApplicationContext] Unable to locate ApplicationEventMulticaster with name &apos;applicationEventMulticaster&apos;: using default
[org.springframework.context.event.SimpleApplicationEventMulticaster@78c714]
22:56:07,783 INFO [DefaultListableBeanFactory] Pre-instantiating singletons in factory [org.springframework.beans.factory.support.DefaultListableBeanFactory
defining beans [org.apache.activemq.xbean.XBeanBrokerService]; root of BeanFactory hierarchy]
22:56:08,181 INFO [BrokerService] ActiveMQ 4.0.2 JMS Message Broker (bruce.broker1) is starting
22:56:08,181 INFO [BrokerService] For help or more information please see: http://incubator.apache.org/activemq/
22:56:09,989 INFO [JDBCPersistenceAdapter] Database driver recognized: [apache_derby_embedded_jdbc_driver]
22:56:11,026 INFO [JournalPersistenceAdapter] Journal Recovery Started from: Active Journal: using 5 x 20.0 Megs at: /opt/jboss-4.0.5.GA/activemq-data/journal
22:56:11,169 INFO [JournalPersistenceAdapter] Journal Recovered: 0 message(s) in transactions recovered.
22:56:11,489 INFO [TransportServerThreadSupport] Listening for connections at: tcp://rattlesnake:61616
22:56:11,491 WARN [MulticastDiscoveryAgent] brokerName not set
22:56:11,519 INFO [TransportConnector] Connector bruce.broker1 Started
22:56:11,522 INFO [NetworkConnector] Network Connector bridge Started
22:56:11,522 INFO [BrokerService] ActiveMQ JMS Message Broker (bruce.broker1, ID:rattlesnake-59052-1161060967859-1:0) started
22:56:11,556 INFO [RARDeployment] Required license terms exist, view META-INF/ra.xml in .../deploy/jboss-ha-local-jdbc.rar
22:56:11,599 INFO [RARDeployment] Required license terms exist, view META-INF/ra.xml in .../deploy/jboss-ha-xa-jdbc.rar
22:56:11,623 INFO [RARDeployment] Required license terms exist, view META-INF/ra.xml in .../deploy/jboss-local-jdbc.rar
22:56:11,647 INFO [RARDeployment] Required license terms exist, view META-INF/ra.xml in .../deploy/jboss-xa-jdbc.rar
22:56:11,737 INFO [RARDeployment] Required license terms exist, view META-INF/ra.xml in .../deploy/jms/jms-ra.rar
22:56:11,847 INFO [RARDeployment] Required license terms exist, view META-INF/ra.xml in .../deploy/mail-ra.rar
22:56:12,251 INFO [ConnectionFactoryBindingService] Bound ConnectionManager &apos;jboss.jca:service=ConnectionFactoryBinding,name=activemq/QueueConnectionFactory&apos; to
JNDI name &apos;java:activemq/QueueConnectionFactory&apos;
22:56:12,258 INFO [ConnectionFactoryBindingService] Bound ConnectionManager &apos;jboss.jca:service=ConnectionFactoryBinding,name=activemq/TopicConnectionFactory&apos; to
JNDI name &apos;java:activemq/TopicConnectionFactory&apos;
22:56:12,265 INFO [AdminObject] Bound admin object &apos;org.apache.activemq.command.ActiveMQQueue&apos; at &apos;activemq/queue/outbound&apos;
22:56:12,330 INFO [AdminObject] Bound admin object &apos;org.apache.activemq.command.ActiveMQTopic&apos; at &apos;activemq/topic/inbound&apos;
22:56:13,246 INFO [ConnectionFactoryBindingService] Bound ConnectionManager &apos;jboss.jca:service=DataSourceBinding,name=DefaultDS&apos; to JNDI name &apos;java:DefaultDS&apos;
22:56:13,842 INFO [A] Bound to JNDI name: queue/A
22:56:13,845 INFO [B] Bound to JNDI name: queue/B
22:56:13,846 INFO [C] Bound to JNDI name: queue/C
22:56:13,848 INFO [D] Bound to JNDI name: queue/D
22:56:13,850 INFO [ex] Bound to JNDI name: queue/ex
22:56:13,876 INFO [testTopic] Bound to JNDI name: topic/testTopic
22:56:13,879 INFO [securedTopic] Bound to JNDI name: topic/securedTopic
22:56:13,880 INFO [testDurableTopic] Bound to JNDI name: topic/testDurableTopic
22:56:13,883 INFO [testQueue] Bound to JNDI name: queue/testQueue
22:56:13,994 INFO [UILServerILService] JBossMQ UIL service available at : /0.0.0.0:8093
22:56:14,055 INFO [DLQ] Bound to JNDI name: queue/DLQ
22:56:14,375 INFO [ConnectionFactoryBindingService] Bound ConnectionManager &apos;jboss.jca:service=ConnectionFactoryBinding,name=JmsXA&apos; to JNDI name &apos;java:JmsXA&apos;
22:56:14,525 INFO [TomcatDeployer] deploy, ctxPath=/jmx-console, warUrl=.../deploy/jmx-console.war/
22:56:14,991 INFO [Http11BaseProtocol] Starting Coyote HTTP/1.1 on http-0.0.0.0-8080
22:56:15,071 INFO [ChannelSocket] JK: ajp13 listening on /0.0.0.0:8009
22:56:15,082 INFO [JkMain] Jk running ID=0 time=0/25 config=null
22:56:15,108 INFO [Server] JBoss (MX MicroKernel) [4.0.5.GA (build: CVSTag=JBoss_4_0_5_GA date=200605151000)] Started in 26s:398ms

如果在JBoss控制台上看到以上代码,说明ActiveMQ已经成功集成到JBoss中。
可以用自己的JMS测试代码对集成好的应用服务器做相应的测试,具体测试代码将在后面的文章中给出。

参考文献:
[1]Integrating Apache ActiveMQ with JBoss
[2]JBoss Integration
[3]ActiveMQ 实践之路(三) ActiveMQ 4_x +JBoss 4_x 整合篇

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值