ActiveMQ包含了很多features(详见http://activemq.apache.org/features.html ),
不同的需求,不同的环境,需要不同的features,当然需要不同的配置。在这里我只写了最基本的配置,算是抛砖了,希望引出更多关于ActiveMQ的高级配置。
假设已经正确安装ActiveMQ5.0,同时及其IP地址为192.168.1.148,具体使用时可以改为自己的IP。下面讲解的配置实现的features如下:
1. 客户端可以通过tcp://192.168.1.148连接ActiveMQ。
2. 消息持久化保存,重启服务器不会丢失消息。
3. 可以通过http://192.168.1.148:8161/admin监控ActiveMQ服务器
配置
ActiveMQ默认使用的是XML格式配置,从4.0版本开始用MBean的方式实现XML配置,配置文件在${activemq.home}/conf目录下,文件名为activemq.xml。最新的默认配置见
http://svn.apache.org/repos/asf/activemq/trunk/assembly/src/release/conf/activemq.xml 。下面为本篇文章使用的配置,及重要部分的解释。
1. <beans
2. <SPAN class=hilite2>xml</SPAN>ns="http://www.springframework.org/schema/beans"
3. <SPAN class=hilite2>xml</SPAN>ns:amq="http://<SPAN class=hilite1>activemq</SPAN>.org/config/1.0"
4. <SPAN class=hilite2>xml</SPAN>ns:xsi="http://www.w3.org/2001/<SPAN class=hilite2>XML</SPAN>Schema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
5. http://<SPAN class=hilite1>activemq</SPAN>.org/config/1.0 http://<SPAN class=hilite1>activemq</SPAN>.apache.org/schema/<SPAN class=hilite1>activemq</SPAN>-core.xsd
6. http://<SPAN class=hilite1>activemq</SPAN>.apache.org/camel/schema/spring>
7.
8. <!-- persistent="true"表示要持久化存储消息,和子元素persistenceAdapter结合使用 -->
9. <!-- dataDirectory默认的存储持久化数据的目录 -->
10. <!-- brokerName 设置broker的name,在注意在网络上必须是唯一的-->
11. <!-- 更多参考http://<SPAN class=hilite1>activemq</SPAN>.apache.org /xbean-<SPAN class=hilite2>xml</SPAN>-reference-50.html#XBean<SPAN class=hilite2>XML</SPAN>Reference5.0-brokerelement -->
12. <broker <SPAN class=hilite2>xml</SPAN>ns="http://<SPAN class=hilite1>activemq</SPAN>.org/config/1.0" brokerName="192.168.1.148" persistent ="true" dataDirectory="${<SPAN class=hilite1>activemq</SPAN>.base}/data" useShutdownHook="false">
13.
14. <!-- Destination specific policies using destination names or wildcards -->
15. <!-- wildcards意义见http://<SPAN class=hilite1>activemq</SPAN>.apache.org/wildcards.html -->
16. <destinationPolicy>
17. <policyMap>
18. <policyEntries>
19. <!-- 这里使用了wildcards,表示所有以EUCITA开头的topic -->
20. <policyEntry topic="EUCITA.>" producerFlowControl="false" memoryLimit="10mb">
21. <!-- 分发策略 -->
22. <dispatchPolicy>
23. <!-- 按顺序分发 -->
24. <strictOrderDispatchPolicy/>
25. </dispatchPolicy>
26. <!-- 恢复策略-->
27. <subscriptionRecoveryPolicy>
28. <!-- 只恢复最后一个message -->
29. <lastImageSubscriptionRecoveryPolicy/>
30. </subscriptionRecoveryPolicy>
31. </policyEntry>
32. </policyEntries>
33. </policyMap>
34. </destinationPolicy>
35.
36. <!-- The transport connectors <SPAN class=hilite1>ActiveMQ</SPAN> will listen to -->
37. <transportConnectors>
38. <transportConnector name="openwire" uri="tcp://192.168.1.148:61616" discoveryUri="multicast://default"/>
39. <transportConnector name="ssl" uri="ssl://192.168.1.148:61617"/>
40. <transportConnector name="stomp" uri="stomp://192.168.1.148:61613"/>
41. <transportConnector name="xmpp" uri="xmpp://192.168.1.148:61222"/>
42. </transportConnectors>
43.
44. <!-- 消息持久化方式 -->
45. <persistenceAdapter>
46. <amqPersistenceAdapter directory="${<SPAN class=hilite1>activemq</SPAN>.base}/data"/>
47. </persistenceAdapter>
48. </broker>
49.
50. <!-- lets create a command agent to respond to message based admin commands on the <SPAN class=hilite1>ActiveMQ</SPAN>.Agent topic -->
51. <commandAgent <SPAN class=hilite2>xml</SPAN>ns="http://<SPAN class=hilite1>activemq</SPAN>.org/config/1.0"/>
52.
53. <!-- An embedded servlet engine for serving up the Admin console -->
54. <jetty <SPAN class=hilite2>xml</SPAN>ns="http://mortbay.com/schemas/jetty/1.0">
55. <connectors>
56. <nioConnector port="8161" />
57. </connectors>
58.
59. <handlers>
60. <webAppContext contextPath="/admin" resourceBase="${<SPAN class=hilite1>activemq</SPAN>.base}/webapps/admin" logUrlOnStart="true" />
61. <webAppContext contextPath="/demo" resourceBase="${<SPAN class=hilite1>activemq</SPAN>.base}/webapps/demo" logUrlOnStart="true" />
62. </handlers>
63. </jetty>
64. </beans>
注释
关于XML配置中元素的具体信息可以参考http://activemq.apache.org/xbean-xml-reference-50.html 下面介绍本篇配置使用的一些重要元素。
DispathPolicy
ActiveMQ支持3中不同的分发策略(避免翻译了以后误解,这里用原文):
1. <roundRobinDispatchPolicy>:Simple dispatch policy that sends a message to every subscription that matches the message.
2. <simpleDispatchPolicy>:Simple dispatch policy that sends a message to every subscription that matches the message.
3. <strictOrderDispatchPolicy>:Dispatch policy that causes every subscription to see messages in the same order.
SubscriptionRecoveryPolicy
ActiveMQ支持6种恢复策略,可以自行选择使用不同的策略
1. <fixedCountSubscriptionRecoveryPolicy>: keep a fixed count of last messages.
2. <fixedSizedSubscriptionRecoveryPolicy>: keep a fixed amount of memory available in RAM for message history which is evicted in time order.
3. <lastImageSubscriptionRecoveryPolicy>:only keep the last message.
4. <noSubscriptionRecoveryPolicy>:disable recovery of messages.
5. <queryBasedSubscriptionRecoveryPolicy>:perform a user specific query mechanism to load any messages they may have missed.
6. <timedSubscriptionRecoveryPolicy>:keep a timed buffer of messages around in memory and use that to recover new subscriptions.
PersistenceAdapter
http://activemq.apache.org/persistence 讲解了关于persistence的信息。ActiveMQ5.0使用AMQ Message Store 持久化消息,这种方式提供了很好的性能(The AMQ Message Store is an embeddable transactional message storage solution that is extremely fast and reliable.)默认使用该存储方式即可,如果想使用JDBC来存储,可以查找文档配置。
Summary
本篇文章只提供了基本配置信息。如果需要更多的文章,可以查看ActiveMQ的文档。
讲了安装和简单的配置,下一篇将介绍和Sping的整合,以及多个queue,多个topic,多个producer,多个consumer的配置,使用。
原贴地址:http://jinguo.iteye.com/blog/239885
分享到:
相关推荐
activeMQ+spring的简单案例
它最初的创建是为了允许在单元测试中定义代理配置的简化机制,而无需求助于 ActiveMQ 的内部类,或者使用 ActiveMQ XML 配置文件创建许多相似但不同的代理配置。 注意:这些 DSL 处于 pre-alpha 的这个阶段。 验证...
百度spring整合activemq 发现几乎都只是在xml文件配置固定的消息队列而且太麻烦。并没有根据需求进行动态生成主题和队列。本文档参考了纯粹的activemq java代码和百度上的demo,很简洁的实现了动态消息队列的生成和...
logback-spring.xml文件配置,1、异步日志,2、滚动日志,存放固定时长的日志,超过时间的自动删除,3、单个文件超过指定大小,分成多个,防止单个文件过大,查看不方便
activemq-web-console的默认使用方式是通过在activemq.xml中导入jetty.xml配置一个jetty server来实现的。其实activemq-web-console完全可以和activemq-broker分开来部署。 activemq-web-console包含3个apps, 1.一...
ActiveMQ整合MySql实现消息持久化配置文件
请将本maven项目引入你自己的maven项目中(在你自己的pom.xml文件中配置这个项目的gourp和id以及版本号),通过模块化导入,注意把spring-activeMQ.xml加载到容器当中,运行tomcat启动项目,即可看到效果。
Spring支持,以便ActiveMQ可以轻松嵌入到Spring应用程序中,并使用Spring的XML配置机制进行配置 专为高性能集群,客户端 - 服务器,基于对等的通信而设计 CXF和Axis支持,以便ActiveMQ可以轻松地放入这些Web服务...
一键生成webXml、initXml、contextXml等系统配置文件 配置控制生成输出文件(listenter、filter、quartz、activeMQ、redis、webXml、initXml、contextXml) 项目可统计在线人数,无操作超时退出,监听网络请求,...
ActiveMQ插件,用于连接验证 在外部activeMQ服务器中加入验证插件:插件加入地址为activeMQ/lib activeMQ.xml植入的配置文件 < value>http://127.0.0.1:8082/activeMQ/checkSecret</
领域特定语言意味着Apache Camel支持你在的集成开发工具中使用平常的,类型安全的,可自动补全的Java代码来编写路由规则,而不需要大量的XML配置文件。同时,也支持在Spring中使用XML配置定义路由和中介规则。 在...
Spring 之中整合 dubbo、RabbitMQ、Kafka、ActiveMQ、MySQL、 Druid、Redis、Shiro,需要编写一堆堆的*.xml 配置文件; 所以在这样的一个大的历史背景下,很多人开始寻求更加简便的开发,而遗憾的是这种简便的开发...
这与那种复杂的XML配置相比极大简化了规则定义开发。 当然Apache Camel也提供了一个对Spring 配置文件的支持。 Apache Camel 采用URI来描述各种组件,这样你可以很方便地与各种传输或者消息模块进行交互,其中包含...
配置文件 jetty.xml–Server configuration jetty-web.xml–Web App configuration jetty-env.xml–JNDI configuration webdefault.xml–Pre-web.xml configuration override-web.xml–Post-web.xml configuration ...
介绍Camel允许您创建企业集成模式,以通过基于Spring或Blueprint的Xml配置文件或基于Scala DSL,以基于Java的特定于域的语言(或Fluent API)来实现路由和中介规则。 这意味着无论是在Java,Scala还是XML编辑器中,...
接着,需要创建app-context.xml文件,用于配置Spring的应用程序上下文。该文件的内容如下: <?xml version="1.0" encoding="UTF-8"?> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jms=...
ActiveMQ | 消息队列 | [http://activemq.apache.org/](http://activemq.apache.org/) JStorm | 实时流式计算框架 | [http://jstorm.io/](http://jstorm.io/) FastDFS | 分布式文件系统 | ...
- Spring Boot 数据库操作,包括SpringJDBC、JPA、Mybatis注解版 & XML版、MongoDB。其中,每个版本都有其对应的多数据源解决方案。 - springboot-caches - Spring Boot 缓存,包括redis、ehcache、spring-cache...
java企业门户开源WSO2 测试自动化框架 WSO2 测试自动化框架 (TAF) 是一个自动化框架,在部署生命周期的所有阶段均表现相同。...引入单个配置文件来管理所有配置。 通过可插拔模块实现框架扩展能力。 增强的服务器管
Java正则表达式 批量上传--采集 (多个文件夹) The Agile Way hibernate mapping文件中的标记详解:关系标记 ANT 安装使用及build.xml文档模板 inverse和cascade在关联更新中的作用 hibernate ...