ActiveMQ in Action-1.3 Getting started with ActiveMQ- 高飞网

1.3 Getting started with ActiveMQ

2016-05-31 15:13:22.0

1.3 入门

    ActiveMQ入门非常之简单。你只要启动服务,确定它可以接入连接,然后发送消息。ActiveMQ自带了一些简单的例子可以帮助你入门,但你首选要安装Java并下载ActiveMQ。

这部分内容中,你将下载并安装JavaSE,下载并安装ActiveMQ,检查ActiveMQ目录结构,启动ActiveMQ。

1.3.1 下载安装JavaSE

译者略。

1.3.2 下载ActiveMQ

译者略。

1.3.3 查看ActiveMQ目录结构

从命令行工具中,进入activemq主目录,查看目录结构如下:

activemq-all-5.13.2.jar
bin
conf
data
docs
examples
lib
LICENSE
NOTICE
README.txt
webapps
webapps-demo

目录内容非常明显:

activemq-all-5.13.2.jar:包含所有ActiveMQ内容的jar包。放在这里是为了你获取和使用时方便。
bin:这个bin目录包含了ActiveMQ的二进制可执行文件。启动脚本就在这里。
conf:conf目录包含了所有ActiveMQ的配置信息。
data:data目录是日志文件和消息持久化数据存储的地方。
docs:包含了一个简单的index.html文件指向到ActiveMQ的站点。
examples:ActiveMQ的示例程序。这些用以简单而快速地测试ActiveMQ。
lib:lib目录包含ActiveMQ所需的所有类库。
LICENSE:Apache软件基金会(Apache Software Foundation,ASF)所必须的法律许可文件。包含ActiveMQ使用的所有类库的许可。
NOTICE:另外一个出于法律目的文件,包含ActiveMQ使用的所有类库的版权信息。
README.txt:一个包含了新手可以学习使用ActiveMQ文档的url的文件。
webapps:webapps目录包含了ActiveMQ的web控制台程序和一些其他的web示例。
webapps-demo:示例

下一个任务是启动ActiveMQ并使用示例验证。


1.3.4 启动ActiveMQ

下载完并解压了压缩包后,ActiveMQ就可以用了。可执行程序提供了一个基本的配置让你轻松启动它。这就是我们在示例中用到的。那么按下面的方式启动ActiveMQ。

./activemq start

2016-04-28 10:01:39,603 | INFO  | Refreshing org.apache.activemq.xbean.XBeanBrokerFactory$1@190c05e2: startup date [Thu Apr 28 10:01:39 CST 2016]; root of context hierarchy | org.apache.activemq.xbean.XBeanBrokerFactory$1 | WrapperSimpleAppMain
2016-04-28 10:01:42,979 | INFO  | Using Persistence Adapter: KahaDBPersistenceAdapter[/home/www/data/apache-activemq-5.13.2/bin/linux-x86-64/../../data/kahadb] | org.apache.activemq.broker.BrokerService | WrapperSimpleAppMain
2016-04-28 10:01:43,678 | INFO  | KahaDB is version 6 | org.apache.activemq.store.kahadb.MessageDatabase | WrapperSimpleAppMain
2016-04-28 10:01:43,750 | INFO  | Recovering from the journal @1:6045430 | org.apache.activemq.store.kahadb.MessageDatabase | WrapperSimpleAppMain
2016-04-28 10:01:43,767 | INFO  | Recovery replayed 14 operations from the journal in 0.068 seconds. | org.apache.activemq.store.kahadb.MessageDatabase | WrapperSimpleAppMain
2016-04-28 10:01:43,799 | INFO  | PListStore:[/home/www/data/apache-activemq-5.13.2/bin/linux-x86-64/../../data/localhost/tmp_storage] started | org.apache.activemq.store.kahadb.plist.PListStoreImpl | WrapperSimpleAppMain
2016-04-28 10:01:44,041 | INFO  | Apache ActiveMQ 5.13.2 (localhost, ID:iZ25w5rxg9zZ-59923-1461808903886-0:1) is starting | org.apache.activemq.broker.BrokerService | WrapperSimpleAppMain
2016-04-28 10:01:44,291 | INFO  | Listening for connections at: tcp://iZ25w5rxg9zZ:61616?maximumConnections=1000&wireFormat.maxFrameSize=104857600 | org.apache.activemq.transport.TransportServerThreadSupport | WrapperSimpleAppMain
2016-04-28 10:01:44,304 | INFO  | Connector openwire started | org.apache.activemq.broker.TransportConnector | WrapperSimpleAppMain
2016-04-28 10:01:44,338 | INFO  | Listening for connections at: amqp://iZ25w5rxg9zZ:5672?maximumConnections=1000&wireFormat.maxFrameSize=104857600 | org.apache.activemq.transport.TransportServerThreadSupport | WrapperSimpleAppMain
2016-04-28 10:01:44,356 | INFO  | Connector amqp started | org.apache.activemq.broker.TransportConnector | WrapperSimpleAppMain
2016-04-28 10:01:44,388 | INFO  | Listening for connections at: stomp://iZ25w5rxg9zZ:61613?maximumConnections=1000&wireFormat.maxFrameSize=104857600 | org.apache.activemq.transport.TransportServerThreadSupport | WrapperSimpleAppMain
2016-04-28 10:01:44,404 | INFO  | Connector stomp started | org.apache.activemq.broker.TransportConnector | WrapperSimpleAppMain
2016-04-28 10:01:44,423 | INFO  | Listening for connections at: mqtt://iZ25w5rxg9zZ:1883?maximumConnections=1000&wireFormat.maxFrameSize=104857600 | org.apache.activemq.transport.TransportServerThreadSupport | WrapperSimpleAppMain
2016-04-28 10:01:44,445 | INFO  | Connector mqtt started | org.apache.activemq.broker.TransportConnector | WrapperSimpleAppMain
2016-04-28 10:01:44,721 | WARN  | ServletContext@o.e.j.s.ServletContextHandler@6ebd7e65{/,null,STARTING} has uncovered http methods for path: / | org.eclipse.jetty.security.SecurityHandler | WrapperSimpleAppMain
2016-04-28 10:01:44,851 | INFO  | Listening for connections at ws://iZ25w5rxg9zZ:61614?maximumConnections=1000&wireFormat.maxFrameSize=104857600 | org.apache.activemq.transport.ws.WSTransportServer | WrapperSimpleAppMain
2016-04-28 10:01:44,865 | INFO  | Connector ws started | org.apache.activemq.broker.TransportConnector | WrapperSimpleAppMain
2016-04-28 10:01:44,867 | INFO  | Apache ActiveMQ 5.13.2 (localhost, ID:iZ25w5rxg9zZ-59923-1461808903886-0:1) started | org.apache.activemq.broker.BrokerService | WrapperSimpleAppMain
2016-04-28 10:01:44,874 | INFO  | For help or more information please see: http://activemq.apache.org | org.apache.activemq.broker.BrokerService | WrapperSimpleAppMain
2016-04-28 10:01:44,879 | WARN  | Store limit is 102400 mb (current store usage is 5 mb). The data directory: /home/www/data/apache-activemq-5.13.2/bin/linux-x86-64/../../data/kahadb only has 16069 mb of usable space. - resetting to maximum available disk space: 16069 mb | org.apache.activemq.broker.BrokerService | WrapperSimpleAppMain
2016-04-28 10:01:44,883 | WARN  | Temporary Store limit is 51200 mb (current store usage is 0 mb). The data directory: /home/www/data/apache-activemq-5.13.2/bin/linux-x86-64/../../data only has 16064 mb of usable space. - resetting to maximum available disk space: 16064 mb | org.apache.activemq.broker.BrokerService | WrapperSimpleAppMain
2016-04-28 10:01:45,960 | INFO  | No Spring WebApplicationInitializer types detected on classpath | /admin | WrapperSimpleAppMain
2016-04-28 10:01:46,592 | INFO  | ActiveMQ WebConsole available at http://0.0.0.0:8161/ | org.apache.activemq.web.WebConsoleStarter | WrapperSimpleAppMain
2016-04-28 10:01:46,593 | INFO  | ActiveMQ Jolokia REST API available at http://0.0.0.0:8161/api/jolokia/ | org.apache.activemq.web.WebConsoleStarter | WrapperSimpleAppMain
2016-04-28 10:01:46,726 | INFO  | Initializing Spring FrameworkServlet 'dispatcher' | /admin | WrapperSimpleAppMain
2016-04-28 10:01:47,641 | INFO  | No Spring WebApplicationInitializer types detected on classpath | /api | WrapperSimpleAppMain
2016-04-28 10:01:47,991 | INFO  | jolokia-agent: Using policy access restrictor classpath:/jolokia-access.xml | /api | WrapperSimpleAppMain

注意,本书的示例列表,都是基于Max OS X,一个类Unix操作系统。如果读者使用的是Windows,运行任何示例时不用使用console参数。如在windows上运行上面的例子的命令是

bin\activemq.bat

这行命令启动了ActiveMQ服务端,输出中可以看到它和客户端的几种连接协议,名为TCP,SSL,STOMP和XMPP。只要意识到ActiveMQ已经启动,并且通过tcp协议的61616端品对客户端可用即可。这些都是可配的,在第4章会讲到。现在,前面的输出告诉我们,ActiveMQ起来了行正在运行以备我们使用。现在它准备接收消息了。开始发送和接收消息最好的途径是使用ActiveMQ自带的示例。下面的部分会手把手教你。