一:快速上手
1:官方网站下载最新版本,当前最新为5.9.0
2:解压后,打开cmd,进入bin目录,执行:activemq,即可启动。(linux下,输入nohup activemq &)
注意看打出的启动日志。
Loading message broker from: xbean:activemq.xml,这个文件是主要的配置文件。
Using Persistence Adapter: KahaDBPersistenceAdapter,这是一个activemq专用的消息存储器,速度很快的。
Listening for connections at: tcp://collonn-PC:61616?maximumConnections=1000&wireFormat.maxFrameSize=104857600,这是activemq监听的其中一个端口。
ActiveMQ WebConsole available at http://localhost:8161/,这是activemq基于页面的控制台。
3:打开浏览器,输入http://localhost:8161/,选择Manage ActiveMQ broker using the old console,用旧的方式查看和控制activemq更方便。
二:快速进阶
1:进入到activemq_install_dir/config目录,有以下几个重要文件
(1)activemq.xml,在此文件中你可以配置activemq的很多东西,比如将消息持久化到数据库等。
(2)credentials.properties,一些密码,多用于生产和消费的密码认证。
(3)jetty.xml,activemq内置了jetty应用服务器。
(4)jetty-realm.properties,activemq控制台登陆密码。
三:持久化消息到MySQL
1:activemq_install_dir/examples/config目录下有好多示例配置文件可以做参考,如持久化到数据库,安全相关等。
2:将mysql驱动拷贝到activemq_install_dir/lib目录下,并在数据库中创建一个空的数据空的数据库,名称为activemq。
3:修改activemq.xml文件,如下
四:让activemq更安全,认证后才能生产和消费。在activemq.xml文件中加入以下,注意直接加在transportConnectors节点上面即可,文件中引用的密码来自于activemq_install_dir/config/credentials.properties文件,activemq.xml完整内容如下:
五:最终的activemq.xml内容如下
-
<!--
-
Licensed to the Apache Software Foundation (ASF) under one or more
-
contributor license agreements. See the NOTICE file distributed with
-
this work for additional information regarding copyright ownership.
-
The ASF licenses this file to You under the Apache License, Version 2.0
-
(the "License"); you may not use this 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 agreed to in writing, software
-
distributed under the License is distributed on an "AS IS" BASIS,
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-
See the License for the specific language governing permissions and
-
limitations under the License.
-
-->
-
<!-- START SNIPPET: example -->
-
<beans
-
xmlns=
"http://www.springframework.org/schema/beans"
-
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
-
xsi:schemaLocation=
"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
-
http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">
-
-
<!-- Allows us to use system properties as variables in this configuration file -->
-
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
-
<property name="locations">
-
<value>file:${activemq.conf}/credentials.properties
</value>
-
</property>
-
</bean>
-
-
<!--
-
The <broker> element is used to configure the ActiveMQ broker.
-
-->
-
<broker xmlns="http://activemq.apache.org/schema/core" brokerName="localhost">
-
<!--
-
Configure message persistence for the broker. The default persistence
-
mechanism is the KahaDB store (identified by the kahaDB tag).
-
For more information, see:
-
-
http://activemq.apache.org/persistence.html
-
-->
-
<persistenceAdapter>
-
<jdbcPersistenceAdapter dataDirectory="${activemq.data}" dataSource="#mysql-ds"/>
-
</persistenceAdapter>
-
-
<plugins>
-
<!-- Configure authentication; Username, passwords and groups -->
-
<simpleAuthenticationPlugin>
-
<users>
-
<authenticationUser username="admin" password="admin" groups="users,admins"/>
-
</users>
-
</simpleAuthenticationPlugin>
-
</plugins>
-
-
<!--
-
The transport connectors expose ActiveMQ over a given protocol to
-
clients and other brokers. For more information, see:
-
-
http://activemq.apache.org/configuring-transports.html
-
-->
-
<transportConnectors>
-
<!-- DOS protection, limit concurrent connections to 1000 and frame size to 100MB -->
-
<transportConnector name="openwire" uri="tcp://0.0.0.0:61616?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
-
</transportConnectors>
-
-
<!-- destroy the spring context on shutdown to stop jetty -->
-
<shutdownHooks>
-
<bean xmlns="http://www.springframework.org/schema/beans" class="org.apache.activemq.hooks.SpringContextHook" />
-
</shutdownHooks>
-
-
</broker>
-
-
<!-- MySql DataSource Sample Setup -->
-
<bean id="mysql-ds" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
-
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
-
<property name="url" value="jdbc:mysql://localhost/activemq?relaxAutoCommit=true"/>
-
<property name="username" value="root"/>
-
<property name="password" value="sa"/>
-
<property name="maxActive" value="200"/>
-
<property name="poolPreparedStatements" value="true"/>
-
</bean>
-
-
<!--
-
Enable web consoles, REST and Ajax APIs and demos
-
The web consoles requires by default login, you can disable this in the jetty.xml file
-
-
Take a look at ${ACTIVEMQ_HOME}/conf/jetty.xml for more details
-
-->
-
<import resource="jetty.xml"/>
-
-
</beans>
-
<!-- END SNIPPET: example -->