217 lines
11 KiB
XML
217 lines
11 KiB
XML
<?xml version="1.0" encoding="UTF-8"?>
|
||
<!-- ============================================================================= -->
|
||
<!-- Copyright © 2009 Red Hat, Inc. and others. -->
|
||
<!-- -->
|
||
<!-- The text of and illustrations in this document are licensed by Red Hat under -->
|
||
<!-- a Creative Commons Attribution–Share Alike 3.0 Unported license ("CC-BY-SA"). -->
|
||
<!-- -->
|
||
<!-- An explanation of CC-BY-SA is available at -->
|
||
<!-- -->
|
||
<!-- http://creativecommons.org/licenses/by-sa/3.0/. -->
|
||
<!-- -->
|
||
<!-- In accordance with CC-BY-SA, if you distribute this document or an adaptation -->
|
||
<!-- of it, you must provide the URL for the original version. -->
|
||
<!-- -->
|
||
<!-- Red Hat, as the licensor of this document, waives the right to enforce, -->
|
||
<!-- and agrees not to assert, Section 4d of CC-BY-SA to the fullest extent -->
|
||
<!-- permitted by applicable law. -->
|
||
<!-- ============================================================================= -->
|
||
<chapter id="examples">
|
||
<title>运行HornetQ例子</title>
|
||
<para>在HornetQ的<literal>examples</literal>目录下有两组例子,它们是:</para>
|
||
<itemizedlist>
|
||
<listitem>
|
||
<para>JMS例子 - 这些例子展示的是使用JMS发送与接收消息的功能。</para>
|
||
</listitem>
|
||
<listitem>
|
||
<para>Java EE 例子 - 这些例子展示的是与应用服务器的集成,例如MDB,EJB,Servlet等。</para>
|
||
</listitem>
|
||
</itemizedlist>
|
||
<section id="examples.jms">
|
||
<title>JMS例子</title>
|
||
<para>所有JMS都有统一的格式。每个例子都有自己的目录,它的内容包括:</para>
|
||
<itemizedlist>
|
||
<listitem>
|
||
<para><literal>build.xml</literal></para>
|
||
<para>ant的build文件,用来运行例子。</para>
|
||
</listitem>
|
||
<listitem>
|
||
<para><literal>src</literal> 目录</para>
|
||
<para>例子的代码。</para>
|
||
</listitem>
|
||
<listitem>
|
||
<para><literal>server0</literal>配置目录</para>
|
||
<para>它包含了运行服务器所需要的配置文件。有的集群的例子可能有多个这样的目录,如<literal>server0</literal>,
|
||
<literal>server1</literal>等。</para>
|
||
</listitem>
|
||
</itemizedlist>
|
||
<para>在运行每个例子时,都要先启动一个或多个单独的服务器。当例子运行完毕,再将它们停止。</para>
|
||
<para>做为演示我们这里运行queue例子。其它的例子可以参见用户手册。</para>
|
||
<para>首先打开一个命令行窗口(shell),进入到HornetQ的 <literal
|
||
>examples/jms/queue</literal>目录。</para>
|
||
<para>敲入命令<literal>./build.sh</literal> (或者在Windows上<literal>build.bat</literal>),你
|
||
将看到如下的输出:</para>
|
||
<programlisting>Buildfile: build.xml
|
||
|
||
run:
|
||
|
||
init:
|
||
|
||
compile:
|
||
[echo] src.example.dir=/home/andy/projects/hornetq/trunk/examples/jms/queue/src
|
||
[javac] Compiling 5 source files to /home/andy/projects/hornetq/trunk/examples/jms/queue
|
||
/build/classes
|
||
|
||
runExample:
|
||
[java] 10:41:04,149 INFO @main [JMSExample] hornetq.example.runServer is true
|
||
[java] 10:41:04,149 INFO @main [JMSExample] starting server with config 'server0'
|
||
logServerOutput true
|
||
[java] 10:41:04,149 INFO @main [JMSExample] and vm args: -Xms512M,-Xmx512M,-XX:+U
|
||
seParallelGC,-XX:+AggressiveOpts,-XX:+UseFastAccessorMethods,-Djava.util.logging.config.
|
||
file=/home/andy/projects/hornetq/trunk/examples/jms/common/../../../src/config/stand-alone/no
|
||
n-clustered/logging.properties
|
||
[java] org.apache.activemq.jms.example.SpawnedJMSServer out:10:41:08,437 INFO @main [Journal
|
||
StorageManager] AIO journal selected
|
||
[java] org.apache.activemq.jms.example.SpawnedJMSServer out:10:41:08,437 WARN @main [Journal
|
||
StorageManager] AIO wasn't located on this platform, it will fall back to using pure Jav
|
||
a NIO. If your platform is Linux, install LibAIO to enable the AIO journal
|
||
[java] org.apache.activemq.jms.example.SpawnedJMSServer out:10:41:08,437 WARN @main [Securit
|
||
yStoreImpl] It has been detected that the cluster admin password which is used to replic
|
||
ate management operation from one node to the other has not had its password changed fro
|
||
m the installation default. Please see the HornetQ user guide for instructions o
|
||
n how to do this.
|
||
[java] org.apache.activemq.jms.example.SpawnedJMSServer out:10:41:10,941 INFO @main [HornetQCo
|
||
nnectionFactory] read only is false
|
||
[java] org.apache.activemq.jms.example.SpawnedJMSServer out:10:41:10,941 INFO @main [HornetQCo
|
||
nnectionFactory] read only is false
|
||
[java] org.apache.activemq.jms.example.SpawnedJMSServer out:10:41:10,941 INFO @main [HornetQCo
|
||
nnectionFactory] read only is false
|
||
[java] org.apache.activemq.jms.example.SpawnedJMSServer out:10:41:10,991 WARN @main [JMSServ
|
||
erManagerImpl] Binding for java:/ConnectionFactory already exists
|
||
[java] org.apache.activemq.jms.example.SpawnedJMSServer out:10:41:10,991 WARN @main [JMSServ
|
||
erManagerImpl] Binding for java:/XAConnectionFactory already exists
|
||
[java] org.apache.activemq.jms.example.SpawnedJMSServer out:10:41:11,241 INFO @main [Messagi
|
||
ngServerImpl] HornetQ Server version 2.0.0.BETA5 (buzz-buzz, 107) started
|
||
[java] org.apache.activemq.jms.example.SpawnedJMSServer out:10:41:11,241 INFO @main [HornetQBoot
|
||
strapServer] HornetQ server started
|
||
[java] org.apache.activemq.jms.example.SpawnedJMSServer out:STARTED::
|
||
[java] 10:41:11,276 INFO @main [JMSExample] using server0/client-jndi.properties f
|
||
or jndi
|
||
[java] Sent message: This is a text message
|
||
[java] Received message: This is a text message
|
||
[java]
|
||
[java] #####################
|
||
[java] ### SUCCESS! ###
|
||
[java] #####################
|
||
|
||
BUILD SUCCESSFUL
|
||
Total time: 13 seconds
|
||
</programlisting>
|
||
<para>恭喜!你已经成功地运行了你的第一个HornetQ例子。试着运行其它的例子。</para>
|
||
</section>
|
||
<section id="examples.messaging">
|
||
<title>Java EE例子</title>
|
||
<para>Java EE的例子需要首先运行一个JEE应用服务器。这些例子包括MDB,Servlet,EJB等等。你首先要安装JBoss应用服务
|
||
器。参见前面的章节进行安装。</para>
|
||
<para>这里我们将用MDB例子来说明。有关其它例子的详细信息参见用户手册。首先确认JBoss应用服务器已经启动。</para>
|
||
<para>如同其它Java EE例子一样,MDB需要部署到应用服务器。第一,将<literal>JBOSS_HOME</literal>环境变量
|
||
指向你的应用服务器安装目录。如在Linux下:</para>
|
||
<programlisting>export JBOSS_HOME=/home/jbossas5.1/build/output/jboss-5.1.0.GA</programlisting>
|
||
<para>然后就可以进行部署了。在<literal>examples/javaee/mdb</literal>目录下运行:</para>
|
||
<programlisting>./build.sh deploy</programlisting>
|
||
<para>它将创建一个“messaging"的AS配置,并用它来启动AS服务器。</para>
|
||
<para>在命令行窗口你会看到如下的输出:</para>
|
||
<programlisting>Buildfile: build.xml
|
||
|
||
validate-jboss:
|
||
|
||
deploy:
|
||
|
||
deploy-resources:
|
||
[copy] Copying 1 file to /home/andy/projects/jbossas5.1/build/output/jboss-5.1.0.GA
|
||
/server/default-with-hornetq/deploy/hornetq.sar
|
||
[copy] Copying 1 file to /home/andy/projects/jbossas5.1/build/output/jboss-5.1.0.GA
|
||
/server/default-with-hornetq/deploy/hornetq.sar
|
||
|
||
init:
|
||
|
||
compile:
|
||
|
||
jar:
|
||
[jar] Building jar: /home/andy/projects/hornetq/trunk/examples/javaee/mdb/build/mdb-exa
|
||
mple.jar
|
||
|
||
ear:
|
||
[jar] Building jar: /home/andy/projects/hornetq/trunk/examples/javaee/mdb/build/mdb-exa
|
||
mple.ear
|
||
|
||
deploy-ear:
|
||
[copy] Copying 1 file to /home/andy/projects/jbossas5.1/build/output/jboss-5.1.0.GA
|
||
|
||
.......
|
||
|
||
|
||
[exec] 16:01:04,607 INFO [JBossASKernel] Class:javax.jms.MessageListener
|
||
[exec] 16:01:04,607 INFO [JBossASKernel] Added bean(jboss.j2ee:ear=mdb-example.ear,
|
||
jar=mdb-example.jar,name=MessageMDBExample,service=EJB3) to KernelDeployment of:
|
||
mdb-example.jar
|
||
[exec] 16:01:04,702 INFO [EJBContainer] STARTED EJB: org.apache.activemq.javaee.example.server
|
||
.MDBExample ejbName: MessageMDBExample
|
||
[exec] 16:01:09,496 INFO [TomcatDeployment] deploy, ctxPath=/mdb-example
|
||
[exec] 16:01:09,812 WARNING [config] Unable to process deployment descriptor for cont
|
||
ext '/mdb-example'
|
||
[exec] 16:01:09,812 INFO [config] Initializing Mojarra (1.2_12-b01-FCS) for context
|
||
'/mdb-example'
|
||
[exec] 16:01:09,958 INFO [Http11Protocol] Starting Coyote HTTP/1.1 on http-127.0.0.1-
|
||
8080
|
||
[exec] 16:01:09,990 INFO [AjpProtocol] Starting Coyote AJP/1.3 on ajp-127.0.0.1-8009
|
||
[exec] 16:01:10,001 INFO [ServerImpl] JBoss (Microcontainer) [5.1.0.GA (build: SVNTag
|
||
=JBoss_5_1_0_GA date=200905151005)] Started in 6m:21s:797ms
|
||
|
||
</programlisting>
|
||
<para>现在我们可以运行例子了。在<literal>mdb</literal>目录下运行下列命令:</para>
|
||
<programlisting>./build.sh</programlisting>
|
||
<para>你将看到如下输出:</para>
|
||
<programlisting>Buildfile: build.xml
|
||
|
||
run:
|
||
|
||
init:
|
||
|
||
compile:
|
||
|
||
runExample:
|
||
[java] Sent message: This is a text message
|
||
|
||
BUILD SUCCESSFUL
|
||
Total time: 7 seconds</programlisting>
|
||
<para>在JBoss应用服务器端你还会看到如下的输出:</para>
|
||
<programlisting>16:27:54,703 INFO [STDOUT] message This is a text message received</programlisting>
|
||
<para>然后在<literal>mdb</literal>目录下运行下面的命令可以将这个例子卸载。</para>
|
||
<programlisting>./build.sh undeploy</programlisting>
|
||
<para>你将会看到如下的输出:</para>
|
||
<programlisting>Buildfile: build.xml
|
||
|
||
validate-jboss:
|
||
|
||
undeploy:
|
||
|
||
undeploy-misc:
|
||
[delete] Deleting: /home/andy/projects/jbossas5.1/build/output/jboss-5.1.0.GA
|
||
/server/default-with-hornetq/deploy/mdb-example.ear
|
||
[delete] Deleting: /home/andy/projects/jbossas5.1/build/output/jboss-5.1.0.GA
|
||
/server/default-with-hornetq/deploy/hornetq.sar/hornetq-queues.xml
|
||
[delete] Deleting: /home/andy/projects/jbossas5.1/build/output/jboss-5.1.0.GA
|
||
/server/default-with-hornetq/deploy/hornetq.sar/hornetq-jms.xml
|
||
|
||
BUILD SUCCESSFUL
|
||
Total time: 1 second
|
||
</programlisting>
|
||
<para>你还会在窗口输出中看到MDB的应用最終被删除了,如:</para>
|
||
<programlisting>16:36:45,277 INFO [EJBContainer] STOPPED EJB: org.jboss.javaee.example.server.MDBExample
|
||
ejbName: MessageMDBExample
|
||
</programlisting>
|
||
<para>恭喜!你已经成功地部署并运行了一个Java EE的例子。</para>
|
||
</section>
|
||
</chapter>
|