Integrating Apache ActiveMQ with JBoss将Apache ActiveMQ与JBoss集成。Integration with application servers is a common scenario in the enterprise Java world, especially when it comes to messaging. ActiveMQ is a JMS 1.1 compliant, open source, Apache Licensed, message oriented middleware (MOM) with many, many features far beyond the JMS specification. ActiveMQ offers many different points of connectivity, many cross language clients and many pluggable transport protocols including integration with any J2EE 1.4 application server. 与应用服务器的集成是企业Java世界的常见场景,特别是在消息传递方面。ActiveMQ是一个JMS 1.1兼容的、开放源码的、Apache许可的、面向消息的中间件(MOM),它的许多功能远远超出了JMS规范。ActiveMQ提供了许多不同的连接点,许多跨语言客户端和许多可插入传输协议,包括与任何J2EE 1.4应用服务器的集成。 One of the application servers in the open source world is JBoss. A very common requirement is to configure ActiveMQ as the messaging infrastructure within JBoss. Although there is a bit of documentation on this integration, this article seeks to provide much more detail and explanation. So if you have a need to integrate ActiveMQ with JBoss, this article is for you. 开源世界中的一个应用服务器是JBoss。一个非常常见的需求是将ActiveMQ配置为JBoss中的消息传递基础设施。虽然在这个集成方面有一些文档,但是本文试图提供更多的细节和解释。因此,如果您需要将ActiveMQ与JBoss集成,本文就是为您准备的。 This article explains how to configure JBoss to start up ActiveMQ as part of its lifecycle and how to configure the ActiveMQ resource adapter to handle the messaging and transactionality between ActiveMQ and JBoss. 本文解释了如何配置JBoss以启动ActiveMQ作为其生命周期的一部分,以及如何配置ActiveMQ资源适配器来处理ActiveMQ和JBoss之间的消息传递和事务性。 Requirements需求Below are the software requirements for this article with links to download each: 以下是这篇文章的软件要求,每个链接可以下载:
Though this article is using Unix, the installation and integration will work on any platform running Sun Java. It is recommended that each piece of software be downloaded before working through the steps is this article. Once each piece of software has been downloaded, proceed to the first step. 尽管本文使用的是Unix,但是安装和集成将在任何运行Sun Java的平台上运行。建议在完成步骤之前下载每一段软件。一旦每个软件都被下载下来,就开始第一步。 Install the J2SE 1.5安装J2SE 1.5The first step in this process is to install Java 1.5 and verify that it runs correctly. Using the link above, find, download and install the correct version of Java for your platform. Once Java is installed and in the PATH, test it to see that it runs correctly using the following command: 这个过程的第一步是安装Java 1.5,并验证它是否正确运行。使用上面的链接,找到、下载并安装正确版本的Java平台。一旦安装了Java并在路径中进行测试,就可以测试它是否正确地使用以下命令: $ java -version java version "1.5.0_06" Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-112) Java HotSpot(TM) Client VM (build 1.5.0_06-64, mixed mode, sharing) Depending upon your platform and the exact build number of Java 1.5, your output may vary slightly. As long as it's Java 1.5 and the version information is output, you should be ready to proceed to the next step. 根据您的平台和Java 1.5的确切构建数量,您的输出可能略有不同。只要是Java 1.5和版本信息是输出,您就应该准备好进行下一步。 Install Apache Ant安装Apache AntThe second step is to install Apache Ant. Simply download it using the link above, expand somewhere on your hard drive and place the 第二步是安装Apache Ant。只需使用上面的链接下载它,在您的硬盘上进行扩展,并将bin目录放置在路径中。这将允许您快速地使用下面的命令来测试它: $ ant -version Apache Ant version 1.6.2 compiled on July 16 2004 As long as you see the version output above, Ant should be usable. If you did not see the version output or received an error, consult the Ant documentation or mailing list archives to work out the issue. Please note that Ant is not used until the end of this whole exercise to test the integration. 只要您看到上面的版本输出,Ant应该是可用的。如果您没有看到版本输出或收到错误,请参考Ant文档或邮件列表归档来解决这个问题。请注意,在整个测试结束之前Ant不会被使用,以测试集成。 Install the JBoss Application Server安装JBoss应用服务器。The third step in this process is to install JBoss and make sure it runs correctly before installing and configuring ActiveMQ. Upon downloading JBoss-4.0.4, expand it in a place where it can create a directory. Next, run the server using the following commands: 此过程的第三步是安装JBoss并确保在安装和配置ActiveMQ之前正确运行。下载JBoss-4.0.4后,将其扩展到可以创建目录的地方。接下来,使用以下命令运行服务器: $ cd jboss-4.0.4.GA $ ./bin/run.sh -c default ========================================================================= JBoss Bootstrap Environment JBOSS_HOME: /opt/jboss-4.0.4.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.4.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.4.GA (build: CVSTag=JBoss_4_0_4_GA date=200605151000) 15:34:48,004 INFO [Server] Home Dir: /opt/jboss-4.0.4.GA 15:34:48,005 INFO [Server] Home URL: file:/opt/jboss-4.0.4.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.4.GA/server/default 15:34:48,011 INFO [Server] Server Home URL: file:/opt/jboss-4.0.4.GA/server/default/ 15:34:48,012 INFO [Server] Server Log Dir: /opt/jboss-4.0.4.GA/server/default/log 15:34:48,017 INFO [Server] Server Temp Dir: /opt/jboss-4.0.4.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.4.GA (build: CVSTag=JBoss_4_0_4_GA date=200605151000)] Started in 22s:238ms The first few lines of output from the JBoss startup indicates the configuration being used but the last line is the most important one. It tells you that JBoss has been started successfully on your system. For an extra measure of assurance, visit http://localhost:8080/web-console/ in a web browser to make sure you are able to see the JBoss web console. If you can see this console, everything should be ready to go. JBoss启动的前几行输出表示正在使用的配置,但最后一行是最重要的。它告诉您JBoss已经在您的系统上成功启动了。要想获得额外的保证,可以访问http://localhost:8080/webconsole /在web浏览器中,以确保您能够看到JBoss web控制台。如果你能看到这个控制台,一切都准备好了。 As a side note, the left-hand side of the web-console requires that the Java plugin be properly installed. This is supposed to take place when installing the J2SE, so if it did not work correctly for you, I suggest that you consult some documentation about any errors you may be seeing. The Java plugin is not required for JBoss or ActiveMQ to function properly, it is simply for the JBoss web-console. 作为附带说明,web控制台的左侧要求正确安装Java插件。这应该在安装J2SE时发生,所以如果它不能正确地为您工作,我建议您查阅一些关于您可能看到的错误的文档。JBoss或ActiveMQ不需要Java插件来正常工作,它只是JBoss的web控制台。 Once JBoss is installed properly, shut it down using either the shutdown script or by simply typing ctrl-c to activate the shutdown hook. Once it is shut down, proceed to the next step. 一旦JBoss被正确安装,关闭它使用关闭脚本或者简单地键入ctrl-c来激活关闭钩子。一旦关闭,继续下一步。 Prepare for Integrating Apache ActiveMQ with the JBoss Application Server准备将Apache ActiveMQ与JBoss应用服务器集成。The fourth step is to prepare your environment for integrating ActiveMQ with JBoss. If you haven't done so already, download Apache ActiveMQ using the link above. As of the writing of this article, the latest released version is 4.0.2-RC4. Upon downloading this archive, expand it in a place where it can create a directory, preferably in the same location where JBoss was expanded. Verify that the ActiveMQ RAR file is included using the following commands: 第四个步骤是为将ActiveMQ与JBoss集成在一起准备环境。如果您还没有这样做,请使用上面的链接下载Apache ActiveMQ。在撰写本文时,最新发布的版本是4.0.2-RC4。在下载这个归档文件后,将其扩展到可以创建目录的地方,最好是在JBoss扩展的相同位置。验证ActiveMQ RAR文件是否包含以下命令: $ cd ./incubator-activemq-4.0.2.tar.gz $ jar tvf /opt/incubator-activemq-4.0.2/lib/optional/activemq-ra-4.0.2.rar 0 Mon Sep 25 19:00:50 MDT 2006 META-INF/ 399 Mon Sep 25 19:00:48 MDT 2006 META-INF/MANIFEST.MF 523 Mon Sep 25 13:07:40 MDT 2006 META-INF/DISCLAIMER.txt 11359 Mon Sep 25 13:07:40 MDT 2006 META-INF/LICENSE.txt 20305 Mon Sep 25 13:07:40 MDT 2006 META-INF/ra.xml 2334 Mon Sep 25 13:07:40 MDT 2006 broker-config.xml 70023 Mon Sep 25 19:00:48 MDT 2006 activemq-ra-4.0.2.jar 1351744 Mon Sep 25 19:00:14 MDT 2006 activemq-core-4.0.2.jar 232107 Mon Sep 25 18:22:48 MDT 2006 activeio-core-3.0-beta4.jar 2143211 Tue Aug 01 11:44:50 MDT 2006 derby-10.1.1.0.jar 1901653 Tue Aug 01 11:47:08 MDT 2006 spring-1.2.6.jar 94713 Tue Aug 01 11:47:22 MDT 2006 xbean-spring-2.2.jar 52915 Tue Aug 01 12:22:16 MDT 2006 commons-logging-1.1.jar 16030 Tue Aug 01 12:22:32 MDT 2006 geronimo-j2ee-management_1.0_spec-1.0.jar 329586 Tue Aug 01 12:22:54 MDT 2006 backport-util-concurrent-2.1.jar 358085 Tue Aug 01 12:23:26 MDT 2006 log4j-1.2.12.jar 523 Mon Sep 25 19:00:50 MDT 2006 META-INF/DISCLAIMER.txt 11359 Mon Sep 25 19:00:50 MDT 2006 META-INF/LICENSE.txt This is simply a table of contents of the RAR file. There should only be one reason that this will fail - an incomplete download of the ActiveMQ tarball or zip file. Beyond that, depending on the version you download, some of the library versions may be slightly different. 这只是一个RAR文件的目录。应该只有一个原因会失败——ActiveMQ tarball或zip文件的不完整下载。除此之外,根据您下载的版本,一些库版本可能略有不同。 Now go back to the JBoss installation and create a directory for ActiveMQ in the JBoss deploy directory for the default JBoss context. Below are the commands to achieve this task: 现在回到JBoss安装,在JBoss部署目录中为默认的JBoss上下文创建一个ActiveMQ目录。下面是实现此任务的命令: $ mkdir /opt/jboss-4.0.4.GA/server/default/deploy/activemq-ra.rar $ cd /opt/jboss-4.0.4.GA/server/default/deploy/activemq-ra.rar $ pwd /opt/jboss-4.0.4.GA/server/default/deploy/activemq-ra.rar NOTE: The creation of a directory is not required but is the easiest way to set up the ActiveMQ RAR when you're just getting started. This is due to the flexibility it affords during the development phase for the configuration to be changed very easily. The alternative is to JAR up the directory as a RAR file once the configuration is solid enough that it no longer needs to be changed. But leaving everything in a directory during development is the easiest path. 注意:创建一个目录不是必需的,但是当您刚刚开始创建ActiveMQ RAR时,这是最简单的方法。这是因为它在开发阶段提供的灵活性非常容易改变。另一种方法是,一旦配置足够坚固,不再需要更改,就可以将该目录作为一个RAR文件加到一起。但是在开发过程中把所有内容都放在目录中是最简单的方法。 Now expand the activemq-ra-4.0.2.rar into the current working directory: 现在扩大activemq-ra-4.0.2。rar进入当前工作目录: jar xvf /opt/incubator-activemq-4.0.2/lib/optional/activemq-ra-4.0.2.rar created: META-INF/ inflated: META-INF/MANIFEST.MF inflated: META-INF/DISCLAIMER.txt inflated: META-INF/LICENSE.txt inflated: META-INF/ra.xml inflated: broker-config.xml inflated: activemq-ra-4.0.2.jar inflated: activemq-core-4.0.2.jar inflated: activeio-core-3.0-beta4.jar inflated: derby-10.1.1.0.jar inflated: spring-1.2.6.jar inflated: xbean-spring-2.2.jar inflated: commons-logging-1.1.jar inflated: geronimo-j2ee-management_1.0_spec-1.0.jar inflated: backport-util-concurrent-2.1.jar inflated: log4j-1.2.12.jar inflated: META-INF/DISCLAIMER.txt inflated: META-INF/LICENSE.txt Below is a quick listing of the contents of that directory: 下面是该目录内容的快速列表: $ ls -l total 12848 drwxr-xr-x 6 bsnyder bsnyder 204 Oct 16 16:27 META-INF -rw-r--r-- 1 bsnyder bsnyder 232107 Oct 16 16:27 activeio-core-3.0-beta4.jar -rw-r--r-- 1 bsnyder bsnyder 1351744 Oct 16 16:27 activemq-core-4.0.2.jar -rw-r--r-- 1 bsnyder bsnyder 70023 Oct 16 16:27 activemq-ra-4.0.2.jar -rw-r--r-- 1 bsnyder bsnyder 329586 Oct 16 16:27 backport-util-concurrent-2.1.jar -rw-r--r-- 1 bsnyder bsnyder 2334 Oct 16 16:27 broker-config.xml -rw-r--r-- 1 bsnyder bsnyder 52915 Oct 16 16:27 commons-logging-1.1.jar -rw-r--r-- 1 bsnyder bsnyder 2143211 Oct 16 16:27 derby-10.1.1.0.jar -rw-r--r-- 1 bsnyder bsnyder 16030 Oct 16 16:27 geronimo-j2ee-management_1.0_spec-1.0.jar -rw-r--r-- 1 bsnyder bsnyder 358085 Oct 16 16:27 log4j-1.2.12.jar -rw-r--r-- 1 bsnyder bsnyder 1901653 Oct 16 16:27 spring-1.2.6.jar -rw-r--r-- 1 bsnyder bsnyder 94713 Oct 16 16:27 xbean-spring-2.2.jar Now it's time to configure ActiveMQ. 现在是配置ActiveMQ的时候了。 Configuring Apache ActiveMQ配置Apache ActiveMQThe fifth step is to actually configure ActiveMQ for integration with JBoss. Remember that you should be sitting in the following directory: 第五步是实际配置ActiveMQ来与JBoss集成。记住,你应该坐在下面的目录中: /opt/jboss-4.0.4.GA/server/default/deploy/activemq-ra.rar You may or may not have installed JBoss in 您可能已经或可能没有安装JBoss在/opt中,这并不特别重要。重要的是,您正处于上面创建的目录中,以保存扩展的ActiveMQ RAR文件的内容。 NOTE: A RAR file is a Resource adapter ARchive (RAR). Resource adapters are a concept from the J2EE Connector Architecture (JCA) and are used to interface with Enterprise Information Systems (EIS), i.e., systems external to the application server (e.g., relational databases, mainframes, MOMs, accounting systems, etc.). Resource adapters are often referred to as J2EE connectors and are very similar to the concept of a device driver for, say, a printer in that they contain information specific to connecting to a particular system. The difference with JCA is that that connection has been formalized in specification for Java. So the overall concepts of JCA is for connection to any EIS, but what does that mean? JCA 1.5 provides connectivity and more via the following contracts: 注意:RAR文件是资源适配器存档(RAR)。资源适配器是J2EE连接器体系结构(JCA)中的一个概念,并用于与企业信息系统(EIS)进行接口。,应用服务器的外部系统(例如,关系数据库、大型机、mom、会计系统等)。资源适配器通常被称为J2EE连接器,它们与设备驱动程序的概念非常相似,例如,它们包含特定于连接到特定系统的信息。与JCA的不同之处在于,该连接已在Java规范中正式实现。因此JCA的总体概念是与任何EIS连接,但这意味着什么呢?JCA 1.5通过以下合同提供连接和更多信息: Version 1.0 Contracts 1.0版本的合同 In version 1.0 of the Connector Architecture, three contracts are defined to address the functions mentioned above: 在连接器体系结构的1.0版本中,定义了三个合同来处理上面提到的功能:
New Contracts in Version 1.5 1.5版的新合同。 In version 1.5 of the J2EE Connector Architecture, there are more contracts that a resource adapter must support, as new functionality and features made their way into the specification. A resource adapter can support these four new contracts by implementing the required interfaces defined in the specification for each contract. 在J2EE连接器体系结构的1.5版中,随着新的功能和特性进入规范,资源适配器必须支持更多的契约。资源适配器可以通过实现每个契约规范中定义的所需接口来支持这四种新契约。
Quoted from What's New in the J2EE Connector Architecture 1.5 引用了J2EE连接器体系结构1.5中的新内容。 For more information about JCA, please consult the J2EE Connector Architecture documentation. 有关JCA的更多信息,请参考J2EE连接器体系结构文档。 Open the 打开meta - inf / ra。xml文件并查找以下部分:
META-INF/ra.xml
<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> The section above is used to tell the ActiveMQ RAR where ActiveMQ is located. By default, the in-VM protocol is commented out in favor of the tcp protocol. This will find ActiveMQ running on any interface on the localhost on port 61616. It's ok to just leave this alone if you don't mind the inefficiency of communicating within the JVM via TCP. However, it is recommended that 上面的部分用于告诉ActiveMQ RAR, ActiveMQ位于何处。默认情况下,in- vm协议被注释为支持tcp协议。这将在端口61616上找到本地主机上任何接口上运行的ActiveMQ。如果您不介意在JVM中通过TCP进行通信的效率低下,那么就不要管它了。但是,建议将vm://传输用于嵌入式代理,因此请注释掉tcp://传输并取消对vm的注释://传输。下面是一个例子:
META-INF/ra.xml
<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> Because we're embedding ActiveMQ inside of JBoss, it is more efficient to use the 因为我们在JBoss中嵌入ActiveMQ,所以使用vm://传输,而不是通过tcp //传输来执行消息传递,效率更高。 Now look further down the 现在再看看META-INF/ra。xml文件并找到以下部分:
META-INF/ra.xml
<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> --> </config-property> The section above needs to be changed to uncomment the second to last line and remove/replace the empty element that is above it. Below is an example of how this should be changed: 上面的部分需要更改为uncomment第2行,并删除/替换上面的空元素。下面是一个如何改变的例子:
META-INF/ra.xml
<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>xbean:broker-config.xml</config-property-value> </config-property> This change tells the ActiveMQ RAR to read a configuration file named 这个更改告诉ActiveMQ RAR读取一个名为broker-config的配置文件。xml (xbean:该文件名只是一个指向类的提示,用于读取配置文件),该文件位于类路径上。在本例中,是broker-config。xml文件位于activemq-ra中。rar目录。将更改保存到该文件,然后打开broker-config。xml文件。 The broker-config。xml文件是ActiveMQ配置文件。这是用于配置ActiveMQ的文件。该文件的默认内容是可用的,但是应该根据您的环境定制。关于这个配置有几个注意事项。该文件中最突出的部分是
broker-config.xml
<beans xmlns="http://activemq.org/config/1.0"> <broker useJmx="true"> ... <persistenceAdapter> <journaledJDBC journalLogFiles="5" dataDirectory="activemq-data"/> <!-- To use a different datasource, use th following syntax : --> <!-- <journaledJDBC journalLogFiles="5" dataDirectory="../data" dataSource="#postgres-ds"/> --> </persistenceAdapter> <transportConnectors> <!-- prefixing a connector with discovery: causes the connector to be advertiesed over rendezvous --> <transportConnector uri="tcp://localhost:61616" discoveryUri="multicast://default"/> </transportConnectors> <networkConnectors> <!-- by default just auto discover the other brokers --> <networkConnector uri="multicast://default"/> <!-- <networkConnector uri="static://(tcp://host1:61616,tcp://host2:61616)"/> --> </networkConnectors> </broker> </beans> The first change to this file is to add the brokerName attribute to the broker element and provide a name: 该文件的第一个更改是将brokerName属性添加到代理元素并提供一个名称: <broker useJmx="true" brokerName="bruce.broker1"> In addition, this same name is used further down the configuration to provide a name for the 此外,该名称还用于进一步向下配置,以提供
<transportConnector name="bruce.broker1" uri="tcp://localhost:61616" discoveryUri="multicast://default"/> Now we'll tell ActiveMQ not to initialize JMX because we'll use the existing one that JBoss has: 现在,我们将告诉ActiveMQ不初始化JMX,因为我们将使用JBoss所拥有的现有的JMX: <!-- put the following as the first child of the broker tag --> <managementContext><!-- we'll use an existing one (JBoss) instead of creating one --> <managementContext createConnector="false"/> </managementContext> The 应该重新配置
<!-- put the following as the first child of the beans element --> <bean xmlns="" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/> Now, modify the 现在,修改journaledJDBC元素的dataDirectory属性为:${jboss.server.data.dir}/activemq。 The < transportconnector >元素用于为客户端到代理通信的ActiveMQ代理做广告,而< networkconnector >元素则为broker-to-broker通信做广告的ActiveMQ代理。默认配置是使用ActiveMQ多播传输。这是一个简单的配置,可以让ActiveMQ启动和运行,所以我们暂时把它放在这个位置。 NOTE: There are far more configuration options available for ActiveMQ than are noted here. The configuration above is only enough to just get ActiveMQ up and running, nothing more. For more information on the ActiveMQ configuration, see the ActiveMQ 4.1 XML Reference. 注意:ActiveMQ的配置选项要比这里提到的多得多。上面的配置仅能让ActiveMQ启动和运行,仅此而已。有关ActiveMQ配置的更多信息,请参见ActiveMQ 4.1 XML引用。 Now we just need to start up JBoss to assure that it comes up correctly without error using the same commands we used previously to start JBoss: 现在,我们只需要启动JBoss,以确保它正确无误地使用我们以前启动JBoss时使用的命令: $ cd jboss-4.0.4.GA $ ./bin/run.sh -c default ========================================================================= JBoss Bootstrap Environment JBOSS_HOME: /opt/jboss-4.0.4.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.4.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.4.GA (build: CVSTag=JBoss_4_0_4_GA date=200605151000) 15:34:48,004 INFO [Server] Home Dir: /opt/jboss-4.0.4.GA 15:34:48,005 INFO [Server] Home URL: file:/opt/jboss-4.0.4.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.4.GA/server/default 15:34:48,011 INFO [Server] Server Home URL: file:/opt/jboss-4.0.4.GA/server/default/ 15:34:48,012 INFO [Server] Server Log Dir: /opt/jboss-4.0.4.GA/server/default/log 15:34:48,017 INFO [Server] Server Temp Dir: /opt/jboss-4.0.4.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.4.GA (build: CVSTag=JBoss_4_0_4_GA date=200605151000)] Started in 28s:576ms As long as JBoss comes up without error, you're ready to move on to the next step. 只要JBoss没有出错,您就可以继续下一步了。 Configuring JBoss配置JBossThe sixth step is to configure JBoss to initialize and start ActiveMQ whenever JBoss starts up. This is accomplished using an XML file that abides by the JBoss JCA DTD for data sources. Like most other Java application servers on the market, the JBoss architecture uses the J2EE Connector Architecture to manage connections of any kind including JDBC, JMS, etc. and the JBoss JCA DTD denotes the allowed contents for creating an XML data source instance to configure JBoss JCA. Below is an example XML data source instance for use with JBoss: 第6步是在JBoss启动时配置JBoss初始化并启动ActiveMQ。这是使用一个XML文件实现的,该文件遵循JBoss JCA DTD的数据来源。与市场上大多数其他Java应用服务器一样,JBoss体系结构使用J2EE连接器体系结构来管理任何类型的连接,包括JDBC、JMS等,JBoss JCA DTD表示允许创建XML数据源实例来配置JBoss JCA的允许内容。下面是一个示例XML数据源实例,用于JBoss:
activemq-jms-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>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.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.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.rar'</depends> <attribute name="Type">javax.jms.Topic</attribute> <attribute name="Properties">PhysicalName=topic.inbound</attribute> </mbean> </connection-factories> This XML instance configures a JMS 这个XML实例配置了一个JMS QueueConnectionFactory和一个JMS TopicConnectionFactory,并通过JNDI提供它们。在这个文件中也定义了一些{{AdminObject}},用于指定主题和队列。该文件应该被放入JBoss部署目录中。它的名称(*-ds.xml)将会导致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.4.GA (build: CVSTag=JBoss_4_0_4_GA date=200605151000) 22:55:48,690 INFO [Server] Home Dir: /opt/jboss-4.0.4.GA 22:55:48,692 INFO [Server] Home URL: file:/opt/jboss-4.0.4.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.4.GA/server/default 22:55:48,701 INFO [Server] Server Home URL: file:/opt/jboss-4.0.4.GA/server/default/ 22:55:48,702 INFO [Server] Server Log Dir: /opt/jboss-4.0.4.GA/server/default/log 22:55:48,704 INFO [Server] Server Temp Dir: /opt/jboss-4.0.4.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 'messageSource': using default [org.springframework.context.support.DelegatingMessageSource@5fee96] 22:56:07,781 INFO [ClassPathXmlApplicationContext] Unable to locate ApplicationEventMulticaster with name 'applicationEventMulticaster': 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.4.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 'jboss.jca:service=ConnectionFactoryBinding,name=activemq/QueueConnectionFactory' to JNDI name 'java:activemq/QueueConnectionFactory' 22:56:12,258 INFO [ConnectionFactoryBindingService] Bound ConnectionManager 'jboss.jca:service=ConnectionFactoryBinding,name=activemq/TopicConnectionFactory' to JNDI name 'java:activemq/TopicConnectionFactory' 22:56:12,265 INFO [AdminObject] Bound admin object 'org.apache.activemq.command.ActiveMQQueue' at 'activemq/queue/outbound' 22:56:12,330 INFO [AdminObject] Bound admin object 'org.apache.activemq.command.ActiveMQTopic' at 'activemq/topic/inbound' 22:56:13,246 INFO [ConnectionFactoryBindingService] Bound ConnectionManager 'jboss.jca:service=DataSourceBinding,name=DefaultDS' to JNDI name 'java:DefaultDS' 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 'jboss.jca:service=ConnectionFactoryBinding,name=JmsXA' to JNDI name 'java:JmsXA' 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.4.GA (build: CVSTag=JBoss_4_0_4_GA date=200605151000)] Started in 26s:398ms Note the startup messages from both ActiveMQ and from the 注意,来自ActiveMQ和AdminObject}的启动消息创建了{{ActiveMQQueue和ActiveMQTopic。这些很好地说明了配置是正确的,但是需要进一步验证。下一节将对此进行介绍。 Testing the Integration测试集成The seventh and final step is to perform a slightly more comprehensive smoke test of the integration. This can be accomplished using Apache Ant via the examples that come with the ActiveMQ binary distribution. An Ant build.xml file is included which provides easy access to a simple consumer and a simple producer. The producer will be used to send messages that are received by the consumer. To proceed with this testing, just follow the steps below: 第七步和最后一步是对集成进行稍微全面的烟雾测试。这可以通过使用ActiveMQ二进制发行版的例子来实现。一个Ant构建。包含xml文件,它为简单的使用者和简单的生产者提供了方便的访问。生产者将被用来发送由消费者接收的消息。要进行这个测试,请按照下面的步骤:
Step 1 above just starts up JBoss. Step 2 above starts up a simple message consumer that comes with ActiveMQ. Step 3 above starts up a simple message producer that comes with ActiveMQ. Though the message consumer and message producer are simple utilities, the each one accepts many parameters making them extremely useful for testing ActiveMQ configurations. 上面的步骤1启动了JBoss。上面的步骤2启动了一个带有ActiveMQ的简单消息消费者。上面的步骤3启动了一个带有ActiveMQ的简单消息生成器。虽然消息使用者和消息生产者是简单的实用程序,但它们都接受许多参数,使它们对测试ActiveMQ配置非常有用。 To paraphrase, what just happened was that the message producer sent 10 messages to the TEST.FOO destination and the message consumer received 10 messages from the TEST.FOO destination. Despite being a simple test, it does utilize the ActiveMQ broker, albeit only on a single machine. The next logical step is to set up a full network of ActiveMQ brokers. 转述一下,刚才发生的事情是,消息生产者向测试发送了10条消息。FOO目的地和消息使用者从测试中接收了10条消息。FOO的目的地。尽管是一个简单的测试,但它确实利用了ActiveMQ代理,尽管只是在一台机器上。下一个逻辑步骤是建立一个完整的ActiveMQ代理网络。 After setting up one broker within one instance of JBoss, setting up another is made much easier, but requires another machine or operating system instance. But that's a whole separate article and something to address another day. 在JBoss的一个实例中设置一个代理之后,设置另一个代理要容易得多,但是需要另一个机器或操作系统实例。但这是一篇完整的文章,是另一篇文章。 Conclusion结论What has been demonstrated here is the integration of ActiveMQ with the JBoss application server. This integration is quite common and performed by many enterprises. I hope that this was helpful to people interested in the integration of ActiveMQ with JBoss application server. If you have any questions or are interested in consulting services surrounding ActiveMQ, please contact us for more information. 这里演示的是ActiveMQ与JBoss应用服务器的集成。这种集成是很常见的,由许多企业执行。我希望这有助于人们对ActiveMQ与JBoss应用服务器的集成感兴趣。如果您有任何问题或有兴趣咨询有关ActiveMQ的服务,请与我们联系以获取更多的信息。 Resources资源Below are the configurations for use with both Spring 1.x and Spring 2.x: 下面是在Spring 1中使用的配置。x和Spring 2. x: |