ActiveMQ基本教程 ActiveMQ持久化 ActiveMQ安全

一:快速上手

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内容如下


 
 
  1. <!--
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. -->
  15. <!-- START SNIPPET: example -->
  16. <beans
  17. xmlns= "http://www.springframework.org/schema/beans"
  18. xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance"
  19. xsi:schemaLocation= "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
  20. http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">
  21. <!-- Allows us to use system properties as variables in this configuration file -->
  22. <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
  23. <property name="locations">
  24. <value>file:${activemq.conf}/credentials.properties </value>
  25. </property>
  26. </bean>
  27. <!--
  28. The <broker> element is used to configure the ActiveMQ broker.
  29. -->
  30. <broker xmlns="http://activemq.apache.org/schema/core" brokerName="localhost">
  31. <!--
  32. Configure message persistence for the broker. The default persistence
  33. mechanism is the KahaDB store (identified by the kahaDB tag).
  34. For more information, see:
  35. http://activemq.apache.org/persistence.html
  36. -->
  37. <persistenceAdapter>
  38. <jdbcPersistenceAdapter dataDirectory="${activemq.data}" dataSource="#mysql-ds"/>
  39. </persistenceAdapter>
  40. <plugins>
  41. <!-- Configure authentication; Username, passwords and groups -->
  42. <simpleAuthenticationPlugin>
  43. <users>
  44. <authenticationUser username="admin" password="admin" groups="users,admins"/>
  45. </users>
  46. </simpleAuthenticationPlugin>
  47. </plugins>
  48. <!--
  49. The transport connectors expose ActiveMQ over a given protocol to
  50. clients and other brokers. For more information, see:
  51. http://activemq.apache.org/configuring-transports.html
  52. -->
  53. <transportConnectors>
  54. <!-- DOS protection, limit concurrent connections to 1000 and frame size to 100MB -->
  55. <transportConnector name="openwire" uri="tcp://0.0.0.0:61616?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
  56. </transportConnectors>
  57. <!-- destroy the spring context on shutdown to stop jetty -->
  58. <shutdownHooks>
  59. <bean xmlns="http://www.springframework.org/schema/beans" class="org.apache.activemq.hooks.SpringContextHook" />
  60. </shutdownHooks>
  61. </broker>
  62. <!-- MySql DataSource Sample Setup -->
  63. <bean id="mysql-ds" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
  64. <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
  65. <property name="url" value="jdbc:mysql://localhost/activemq?relaxAutoCommit=true"/>
  66. <property name="username" value="root"/>
  67. <property name="password" value="sa"/>
  68. <property name="maxActive" value="200"/>
  69. <property name="poolPreparedStatements" value="true"/>
  70. </bean>
  71. <!--
  72. Enable web consoles, REST and Ajax APIs and demos
  73. The web consoles requires by default login, you can disable this in the jetty.xml file
  74. Take a look at ${ACTIVEMQ_HOME}/conf/jetty.xml for more details
  75. -->
  76. <import resource="jetty.xml"/>
  77. </beans>
  78. <!-- END SNIPPET: example -->


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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值